diff --git a/src/net/common/senderhelper.cpp b/src/net/common/senderhelper.cpp index 2e51c339..010fe45a 100644 --- a/src/net/common/senderhelper.cpp +++ b/src/net/common/senderhelper.cpp @@ -41,25 +41,17 @@ void SenderHelper::Send(boost::shared_ptr session, boost::shared_ptr packet) { if (packet && session) { - boost::shared_ptr tmpManager; + SendDataManager &tmpManager = session->GetSendDataManager(); { - // First: lock map of all queues. Locate/insert queue. - boost::mutex::scoped_lock lock(m_sendQueueMapMutex); - SendQueueMap::iterator pos = m_sendQueueMap.find(session->GetId()); - if (pos == m_sendQueueMap.end()) - pos = m_sendQueueMap.insert(SendQueueMap::value_type(session->GetId(), boost::shared_ptr(new SendDataManager))).first; - tmpManager = pos->second; - } - { - // Second: Add packet to specific queue. - boost::mutex::scoped_lock lock(tmpManager->dataMutex); - if (tmpManager->GetAllocated() <= MAX_SEND_BUF_SIZE) { - InternalStorePacket(*tmpManager, packet); + // First: Add packet to specific queue. + boost::mutex::scoped_lock lock(tmpManager.dataMutex); + if (tmpManager.GetAllocated() <= MAX_SEND_BUF_SIZE) { + InternalStorePacket(tmpManager, packet); } } { - // Third: Activate async send, if needed. - tmpManager->AsyncSendNextPacket(session->GetAsioSocket()); + // Second: Activate async send, if needed. + tmpManager.AsyncSendNextPacket(session->GetAsioSocket()); } } } @@ -68,45 +60,27 @@ void SenderHelper::Send(boost::shared_ptr session, const NetPacketList &packetList) { if (!packetList.empty() && session) { - boost::shared_ptr tmpManager; + SendDataManager &tmpManager = session->GetSendDataManager(); { - // First: lock map of all queues. Locate/insert queue. - boost::mutex::scoped_lock lock(m_sendQueueMapMutex); - SendQueueMap::iterator pos = m_sendQueueMap.find(session->GetId()); - if (pos == m_sendQueueMap.end()) - pos = m_sendQueueMap.insert(SendQueueMap::value_type(session->GetId(), boost::shared_ptr(new SendDataManager))).first; - tmpManager = pos->second; - } - { - // Second: Add packets to specific queue. - boost::mutex::scoped_lock lock(tmpManager->dataMutex); - if (tmpManager->GetAllocated() <= MAX_SEND_BUF_SIZE) { + // First: Add packets to specific queue. + boost::mutex::scoped_lock lock(tmpManager.dataMutex); + if (tmpManager.GetAllocated() <= MAX_SEND_BUF_SIZE) { NetPacketList::const_iterator i = packetList.begin(); NetPacketList::const_iterator end = packetList.end(); while (i != end) { if (*i) - InternalStorePacket(*tmpManager, *i); + InternalStorePacket(tmpManager, *i); ++i; } } } { - // Third: Activate async send, if needed. - tmpManager->AsyncSendNextPacket(session->GetAsioSocket()); + // Second: Activate async send, if needed. + tmpManager.AsyncSendNextPacket(session->GetAsioSocket()); } } } -void -SenderHelper::SignalSessionTerminated(unsigned sessionId) -{ - boost::mutex::scoped_lock lock(m_sendQueueMapMutex); - - SendQueueMap::iterator pos = m_sendQueueMap.find(sessionId); - if (pos != m_sendQueueMap.end()) - m_sendQueueMap.erase(pos); -} - void SenderHelper::InternalStorePacket(SendDataManager &tmpManager, boost::shared_ptr packet) { diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 1365b317..02d8748b 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -94,8 +94,7 @@ public: // A serious send error should trigger a read error or a read // returning 0 afterwards, and we will handle this error. } - virtual void SignalSessionTerminated(unsigned session) { - m_server.GetSender().SignalSessionTerminated(session); + virtual void SignalSessionTerminated(unsigned /*session*/) { } virtual void SignalChatBotMessage(const string &msg) { diff --git a/src/net/common/sessiondata.cpp b/src/net/common/sessiondata.cpp index 3739969d..7c01bd48 100644 --- a/src/net/common/sessiondata.cpp +++ b/src/net/common/sessiondata.cpp @@ -18,6 +18,7 @@ ***************************************************************************/ #include +#include #include using namespace std; @@ -29,6 +30,7 @@ SessionData::SessionData(boost::shared_ptr sock, S m_autoDisconnectTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::auto_start), m_callback(cb), m_authSession(NULL), m_curAuthStep(0) { + m_sendDataManager.reset(new SendDataManager); } SessionData::~SessionData() @@ -232,13 +234,6 @@ SessionData::SetClientAddr(const std::string &addr) m_clientAddr = addr; } -ReceiveBuffer & -SessionData::GetReceiveBuffer() -{ - // mutex protection, if needed, within buffer. - return m_receiveBuffer; -} - void SessionData::ResetActivityTimer() { diff --git a/src/net/senderhelper.h b/src/net/senderhelper.h index 156d34a7..0fd9e1fd 100644 --- a/src/net/senderhelper.h +++ b/src/net/senderhelper.h @@ -36,20 +36,13 @@ public: void Send(boost::shared_ptr session, boost::shared_ptr packet); void Send(boost::shared_ptr session, const NetPacketList &packetList); - void SignalSessionTerminated(unsigned sessionId); - protected: void InternalStorePacket(SendDataManager &tmpManager, boost::shared_ptr packet); - typedef std::map > SendQueueMap; - private: SenderCallback &m_callback; boost::shared_ptr m_ioService; - - SendQueueMap m_sendQueueMap; - mutable boost::mutex m_sendQueueMapMutex; }; #endif diff --git a/src/net/sessiondata.h b/src/net/sessiondata.h index 3a9f2d13..ffbd42fd 100644 --- a/src/net/sessiondata.h +++ b/src/net/sessiondata.h @@ -38,6 +38,7 @@ typedef unsigned SessionId; struct Gsasl; struct Gsasl_session; +class SendDataManager; class SessionData { @@ -76,7 +77,12 @@ public: const std::string &GetClientAddr() const; void SetClientAddr(const std::string &addr); - ReceiveBuffer &GetReceiveBuffer(); + ReceiveBuffer &GetReceiveBuffer() { + return m_receiveBuffer; + } + SendDataManager &GetSendDataManager() { + return *m_sendDataManager; + } void ResetActivityTimer(); unsigned GetActivityTimerElapsedSec() const; @@ -85,6 +91,8 @@ public: unsigned GetAutoDisconnectTimerElapsedSec() const; protected: + SessionData(const SessionData &other); + SessionData &operator=(const SessionData &other); void InternalClearAuthSession(); private: @@ -94,6 +102,7 @@ private: State m_state; std::string m_clientAddr; ReceiveBuffer m_receiveBuffer; + boost::shared_ptr m_sendDataManager; bool m_readyFlag; bool m_wantsLobbyMsg; boost::timers::portable::microsec_timer m_activityTimer;