Moving send buf limitation to its proper place.

This commit is contained in:
lotodore
2011-02-19 15:19:50 +00:00
parent f7315cd9e5
commit b824b8beb7
2 changed files with 15 additions and 17 deletions
-4
View File
@@ -44,9 +44,7 @@ SenderHelper::Send(boost::shared_ptr<SessionData> session, boost::shared_ptr<Net
SendDataManager &tmpManager = session->GetSendDataManager(); SendDataManager &tmpManager = session->GetSendDataManager();
// Add packet to specific queue. // Add packet to specific queue.
boost::mutex::scoped_lock lock(tmpManager.dataMutex); boost::mutex::scoped_lock lock(tmpManager.dataMutex);
if (tmpManager.GetAllocated() <= MAX_SEND_BUF_SIZE) {
InternalStorePacket(tmpManager, packet); InternalStorePacket(tmpManager, packet);
}
// Activate async send, if needed. // Activate async send, if needed.
tmpManager.AsyncSendNextPacket(session->GetAsioSocket()); tmpManager.AsyncSendNextPacket(session->GetAsioSocket());
} }
@@ -59,7 +57,6 @@ SenderHelper::Send(boost::shared_ptr<SessionData> session, const NetPacketList &
SendDataManager &tmpManager = session->GetSendDataManager(); SendDataManager &tmpManager = session->GetSendDataManager();
// Add packets to specific queue. // Add packets to specific queue.
boost::mutex::scoped_lock lock(tmpManager.dataMutex); boost::mutex::scoped_lock lock(tmpManager.dataMutex);
if (tmpManager.GetAllocated() <= MAX_SEND_BUF_SIZE) {
NetPacketList::const_iterator i = packetList.begin(); NetPacketList::const_iterator i = packetList.begin();
NetPacketList::const_iterator end = packetList.end(); NetPacketList::const_iterator end = packetList.end();
while (i != end) { while (i != end) {
@@ -67,7 +64,6 @@ SenderHelper::Send(boost::shared_ptr<SessionData> session, const NetPacketList &
InternalStorePacket(tmpManager, *i); InternalStorePacket(tmpManager, *i);
++i; ++i;
} }
}
// Activate async send, if needed. // Activate async send, if needed.
tmpManager.AsyncSendNextPacket(session->GetAsioSocket()); tmpManager.AsyncSendNextPacket(session->GetAsioSocket());
} }
+3 -1
View File
@@ -28,7 +28,7 @@
#define SEND_BUF_FIRST_ALLOC_CHUNKSIZE 4096 #define SEND_BUF_FIRST_ALLOC_CHUNKSIZE 4096
#define MAX_SEND_BUF_SIZE SEND_BUF_FIRST_ALLOC_CHUNKSIZE * 1000 #define MAX_SEND_BUF_SIZE SEND_BUF_FIRST_ALLOC_CHUNKSIZE * 256
class SendDataManager : public boost::enable_shared_from_this<SendDataManager> class SendDataManager : public boost::enable_shared_from_this<SendDataManager>
@@ -52,12 +52,14 @@ public:
if (0 == allocAmount) { if (0 == allocAmount) {
allocAmount = (size_t)SEND_BUF_FIRST_ALLOC_CHUNKSIZE; allocAmount = (size_t)SEND_BUF_FIRST_ALLOC_CHUNKSIZE;
} }
if (allocAmount <= MAX_SEND_BUF_SIZE) {
char *tempBuf = (char *)std::realloc(sendBuf, allocAmount); char *tempBuf = (char *)std::realloc(sendBuf, allocAmount);
if (tempBuf) { if (tempBuf) {
sendBuf = tempBuf; sendBuf = tempBuf;
sendBufAllocated = allocAmount; sendBufAllocated = allocAmount;
retVal = true; retVal = true;
} }
}
return retVal; return retVal;
} }