process received messages one at a time without sleeping between messages

This commit is contained in:
Patrick Strateman
2013-10-28 13:20:21 -07:00
committed by Wladimir J. van der Laan
parent ef14a26b12
commit 7084756f4f
2 changed files with 23 additions and 1 deletions

View File

@@ -3141,6 +3141,9 @@ void static ProcessGetData(CNode* pfrom)
// Track requests for our stuff.
Inventory(inv.hash);
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK)
break;
}
}
@@ -3751,6 +3754,9 @@ bool ProcessMessages(CNode* pfrom)
if (!pfrom->vRecvGetData.empty())
ProcessGetData(pfrom);
// this maintains the order of responses
if (!pfrom->vRecvGetData.empty()) return fOk;
std::deque<CNetMessage>::iterator it = pfrom->vRecvMsg.begin();
while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) {
// Don't bother if send buffer is too full to respond anyway
@@ -3841,6 +3847,8 @@ bool ProcessMessages(CNode* pfrom)
if (!fRet)
printf("ProcessMessage(%s, %u bytes) FAILED\n", strCommand.c_str(), nMessageSize);
break;
}
// In case the connection got shut down, its receive buffer was wiped

View File

@@ -1629,6 +1629,9 @@ void ThreadMessageHandler()
CNode* pnodeTrickle = NULL;
if (!vNodesCopy.empty())
pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())];
bool fSleep = true;
BOOST_FOREACH(CNode* pnode, vNodesCopy)
{
if (pnode->fDisconnect)
@@ -1638,8 +1641,18 @@ void ThreadMessageHandler()
{
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
if (lockRecv)
{
if (!ProcessMessages(pnode))
pnode->CloseSocketDisconnect();
if (pnode->nSendSize < SendBufferSize())
{
if (!pnode->vRecvGetData.empty() || (!pnode->vRecvMsg.empty() && pnode->vRecvMsg[0].complete()))
{
fSleep = false;
}
}
}
}
boost::this_thread::interruption_point();
@@ -1658,7 +1671,8 @@ void ThreadMessageHandler()
pnode->Release();
}
MilliSleep(100);
if (fSleep)
MilliSleep(100);
}
}