summaryrefslogtreecommitdiff
path: root/src/session.hpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-05-26 14:07:35 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-06-07 17:30:26 +0800
commit31b2280f295a9afb86fc53ee534bbf48ecca8903 (patch)
tree0c23459ab32fa3b305eb82c86a949ec07e9b300f /src/session.hpp
parente30f6eb6872d57f7da764690589c2f0c9ffdb53b (diff)
v1, sigabrt on client disconnect
Diffstat (limited to 'src/session.hpp')
-rw-r--r--src/session.hpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/session.hpp b/src/session.hpp
index af5d9ee..9adcfad 100644
--- a/src/session.hpp
+++ b/src/session.hpp
@@ -3,7 +3,9 @@
#include "FileDescriptor.hpp"
#include "chatManager.hpp"
#include "format.hpp"
+#include <atomic>
#include <memory>
+#include <mutex>
#include <netinet/in.h>
#include <optional>
#include <string>
@@ -56,18 +58,19 @@ class CSession {
WRITE
};
+ // no need atomic since they don't change after first set
std::pair<std::jthread, std::shared_ptr<CSession>> *self;
std::shared_ptr<CFileDescriptor> m_sockfd;
sockaddr_in m_addr;
socklen_t m_addrLen = sizeof(m_addr);
- std::string m_name;
+ std::string m_name; // need thread safety if we impl rename later
std::string m_ip;
int m_port;
bool m_isAdmin = false;
std::optional<std::string> m_szReading = std::nullopt;
- bool m_bMuted = false;
- bool m_bDeaf = true; // init as true as we don't want anything during registerSession
+ std::atomic<bool> m_bMuted = false;
+ std::atomic<bool> m_bDeaf = true; // init as true as we don't want anything during registerSession
void recvLoop();
bool registerSession();
@@ -82,5 +85,10 @@ class CSession {
void onSend(const std::string &msg);
#endif
+ mutable std::mutex m_writeMutex;
+ mutable std::mutex m_readMutex;
+ mutable std::mutex m_readingMutex;
+ mutable std::mutex m_mutex;
+
friend class CSessionManager;
};