diff options
author | Patrick Strateman <patrick.strateman@gmail.com> | 2013-10-28 13:20:21 -0700 |
---|---|---|
committer | Patrick Strateman <patrick.strateman@gmail.com> | 2013-11-03 20:25:50 -0800 |
commit | 75ef87dd936cd9c84d9a9fd3afce6198409636c4 (patch) | |
tree | 6d08ffa5ec8ae6e5efd6953c6eed3d154d26155c /src | |
parent | a95a1c06b1823d13e8b685c6b18696ead1d17422 (diff) |
process received messages one at a time without sleeping between messages
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 10 | ||||
-rw-r--r-- | src/net.cpp | 18 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp index ecb9711664..4dc2e5c6ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3155,6 +3155,9 @@ void static ProcessGetData(CNode* pfrom) // Track requests for our stuff. g_signals.Inventory(inv.hash); + + if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK) + break; } } @@ -3841,7 +3844,10 @@ 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 @@ -3929,6 +3935,8 @@ bool ProcessMessages(CNode* pfrom) if (!fRet) LogPrintf("ProcessMessage(%s, %u bytes) FAILED\n", strCommand.c_str(), nMessageSize); + + break; } // In case the connection got shut down, its receive buffer was wiped diff --git a/src/net.cpp b/src/net.cpp index de8543da59..8c0ada8f92 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1540,6 +1540,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) @@ -1549,8 +1552,18 @@ void ThreadMessageHandler() { TRY_LOCK(pnode->cs_vRecvMsg, lockRecv); if (lockRecv) + { if (!g_signals.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(); @@ -1568,8 +1581,9 @@ void ThreadMessageHandler() BOOST_FOREACH(CNode* pnode, vNodesCopy) pnode->Release(); } - - MilliSleep(100); + + if (fSleep) + MilliSleep(100); } } |