From 9229434811316b6390c2197d2b23acb42aefdca6 Mon Sep 17 00:00:00 2001 From: Patrick Strateman Date: Mon, 28 Oct 2013 13:20:21 -0700 Subject: [PATCH] process received messages one at a time without sleeping between messages --- src/main.cpp | 8 ++++++++ src/net.cpp | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 45f10aa374..c6f01357f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3183,6 +3183,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; } } @@ -3804,6 +3807,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::iterator it = pfrom->vRecvMsg.begin(); while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) { // Don't bother if send buffer is too full to respond anyway @@ -3894,6 +3900,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 diff --git a/src/net.cpp b/src/net.cpp index 7ece6c919f..6239c9ac01 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1624,6 +1624,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) @@ -1633,8 +1636,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(); @@ -1653,7 +1666,8 @@ void ThreadMessageHandler() pnode->Release(); } - MilliSleep(100); + if (fSleep) + MilliSleep(100); } }