Browse Source

Merge pull request #3180 from pstratem/processgetdata

Reduce latency in network processing
0.10
Gavin Andresen 11 years ago
parent
commit
97f844dd95
  1. 8
      src/main.cpp
  2. 14
      src/net.cpp

8
src/main.cpp

@ -3155,6 +3155,9 @@ void static ProcessGetData(CNode* pfrom) @@ -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;
}
}
@ -3842,6 +3845,9 @@ bool ProcessMessages(CNode* pfrom) @@ -3842,6 +3845,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
@ -3929,6 +3935,8 @@ bool ProcessMessages(CNode* pfrom) @@ -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

14
src/net.cpp

@ -1540,6 +1540,9 @@ void ThreadMessageHandler() @@ -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() @@ -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();
@ -1569,6 +1582,7 @@ void ThreadMessageHandler() @@ -1569,6 +1582,7 @@ void ThreadMessageHandler()
pnode->Release();
}
if (fSleep)
MilliSleep(100);
}
}

Loading…
Cancel
Save