diff --git a/src/net/common/senddatamanager.cpp b/src/net/common/senddatamanager.cpp index a1f2ac86..4ceace04 100644 --- a/src/net/common/senddatamanager.cpp +++ b/src/net/common/senddatamanager.cpp @@ -44,6 +44,7 @@ SendDataManager::HandleWrite(boost::shared_ptr soc { if (!error) { // Successfully sent the data. + boost::mutex::scoped_lock lock(dataMutex); curWriteBufUsed = 0; // Send more data, if available. AsyncSendNextPacket(socket); @@ -53,7 +54,6 @@ SendDataManager::HandleWrite(boost::shared_ptr soc void SendDataManager::AsyncSendNextPacket(boost::shared_ptr socket) { - boost::mutex::scoped_lock lock(dataMutex); if (!curWriteBufUsed) { // Swap buffers and send data. boost::swap(curWriteBuf, sendBuf); diff --git a/src/net/common/senderhelper.cpp b/src/net/common/senderhelper.cpp index 010fe45a..8f5aa29e 100644 --- a/src/net/common/senderhelper.cpp +++ b/src/net/common/senderhelper.cpp @@ -42,17 +42,13 @@ SenderHelper::Send(boost::shared_ptr session, boost::shared_ptrGetSendDataManager(); - { - // First: Add packet to specific queue. - boost::mutex::scoped_lock lock(tmpManager.dataMutex); - if (tmpManager.GetAllocated() <= MAX_SEND_BUF_SIZE) { - InternalStorePacket(tmpManager, packet); - } - } - { - // Second: Activate async send, if needed. - tmpManager.AsyncSendNextPacket(session->GetAsioSocket()); + // Add packet to specific queue. + boost::mutex::scoped_lock lock(tmpManager.dataMutex); + if (tmpManager.GetAllocated() <= MAX_SEND_BUF_SIZE) { + InternalStorePacket(tmpManager, packet); } + // Activate async send, if needed. + tmpManager.AsyncSendNextPacket(session->GetAsioSocket()); } } @@ -61,23 +57,19 @@ SenderHelper::Send(boost::shared_ptr session, const NetPacketList & { if (!packetList.empty() && session) { SendDataManager &tmpManager = session->GetSendDataManager(); - { - // 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); - ++i; - } + // 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); + ++i; } } - { - // Second: Activate async send, if needed. - tmpManager.AsyncSendNextPacket(session->GetAsioSocket()); - } + // Activate async send, if needed. + tmpManager.AsyncSendNextPacket(session->GetAsioSocket()); } }