From 31b2280f295a9afb86fc53ee534bbf48ecca8903 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 26 May 2025 14:07:35 +0800 Subject: v1, sigabrt on client disconnect --- src/session.hpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/session.hpp') 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 #include +#include #include #include #include @@ -56,18 +58,19 @@ class CSession { WRITE }; + // no need atomic since they don't change after first set std::pair> *self; std::shared_ptr 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 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 m_bMuted = false; + std::atomic 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; }; -- cgit v1.2.3