summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-06-12 20:01:31 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-06-12 20:01:48 +0800
commite591313575c63810bb9683cbad4500df1cb50cf1 (patch)
tree05d97e22cfcb76d3398e0a45172045b7c0c82779
parent9d1452447481d45344a1e33446ad9a418e9ea64f (diff)
fix(Makefile): -O0 builds
-rw-r--r--Makefile2
-rw-r--r--src/session.cpp59
-rw-r--r--src/session.hpp2
3 files changed, 34 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index 9ff8a96..ee80975 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ CXXFLAGS += -std=c++26 -Oz -s -Wall -Wextra -flto -fPIC -Wpedantic
LDFLAGS += -Wl,--as-needed,-z,now,-z,pack-relative-relocs
# Debug flags
-DEBUG_CXXFLAGS = -std=c++26 -g3 -O1 -Wall -Wextra -fno-lto -fPIC -DDEBUG -fsanitize=thread -fno-omit-frame-pointer -pthread
+DEBUG_CXXFLAGS = -std=c++26 -g3 -O0 -Wall -Wextra -fno-lto -fPIC -DDEBUG -fsanitize=thread -fno-omit-frame-pointer -pthread
DEBUG_LDFLAGS = -Wl,--no-as-needed,-z,now,-z,pack-relative-relocs -fsanitize=thread -lpthread
# Address Sanitizer Debug flags (run with make asan)
diff --git a/src/session.cpp b/src/session.cpp
index aa6147c..84f1824 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -214,34 +214,6 @@ bool CSession::isValid() {
return getsockopt(m_sockfd->get(), SOL_SOCKET, SO_ERROR, &err, &size) >= 0 && err == 0;
}
-template <typename... Args>
-bool CSession::write(std::format_string<Args...> fmt, Args &&...args) {
- if (m_bDeaf)
- return false;
- return write(NONE, fmt, std::forward<Args>(args)...);
-}
-
-template <typename... Args>
-bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&...args) {
- if (m_bDeaf)
- return false;
-
- std::string msg = NFormatter::fmt(type, fmt, std::forward<Args>(args)...);
- if (m_szReading) {
- msg.insert(0, "\r");
- msg.append(*m_szReading);
- }
-
- if (send(m_sockfd->get(), msg.c_str(), msg.size(), 0) < 0) {
- onErrno(WRITE);
- return false;
- }
-#ifdef DEBUG
- onSend(msg);
-#endif
- return true;
-}
-
bool CSession::write(const std::string &msg) {
return write("{}", msg);
}
@@ -271,3 +243,34 @@ bool CSession::isAdmin() const {
void CSession::setSelf(std::pair<std::jthread, std::shared_ptr<CSession>> *self) {
this->self = self;
}
+
+template <typename... Args>
+bool CSession::write(std::format_string<Args...> fmt, Args &&...args) {
+ if (m_bDeaf)
+ return false;
+ return write(NONE, fmt, std::forward<Args>(args)...);
+}
+
+template <typename... Args>
+bool CSession::write(eFormatType type, std::format_string<Args...> fmt, Args &&...args) {
+ if (m_bDeaf)
+ return false;
+
+ std::string msg = NFormatter::fmt(type, fmt, std::forward<Args>(args)...);
+ if (m_szReading) {
+ msg.insert(0, "\r");
+ msg.append(*m_szReading);
+ }
+
+ if (send(m_sockfd->get(), msg.c_str(), msg.size(), 0) < 0) {
+ onErrno(WRITE);
+ return false;
+ }
+#ifdef DEBUG
+ onSend(msg);
+#endif
+ return true;
+}
+
+template bool CSession::write<const std::string &>(std::format_string<const std::string &>, const std::string &);
+template bool CSession::write<const std::string &>(eFormatType, std::format_string<const std::string &>, const std::string &);
diff --git a/src/session.hpp b/src/session.hpp
index af5d9ee..7747c02 100644
--- a/src/session.hpp
+++ b/src/session.hpp
@@ -3,11 +3,13 @@
#include "FileDescriptor.hpp"
#include "chatManager.hpp"
#include "format.hpp"
+#include <format>
#include <memory>
#include <netinet/in.h>
#include <optional>
#include <string>
#include <thread>
+#include <sys/socket.h>
class CSession {
public: