mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Some fixes to CNetMessage processing
* Change CNode::vRecvMsg to be a deque instead of a vector (less copying) * Make sure to acquire cs_vRecvMsg in CNode::CloseSocketDisconnect (as it may be called without that lock).
This commit is contained in:
committed by
Pieter Wuille
parent
b9ff2970b9
commit
967f24590b
11
src/net.cpp
11
src/net.cpp
@@ -536,7 +536,11 @@ void CNode::CloseSocketDisconnect()
|
||||
printf("disconnecting node %s\n", addrName.c_str());
|
||||
closesocket(hSocket);
|
||||
hSocket = INVALID_SOCKET;
|
||||
vRecvMsg.clear();
|
||||
|
||||
// in case this fails, we'll empty the recv buffer when the CNode is deleted
|
||||
TRY_LOCK(cs_vRecvMsg, lockRecv);
|
||||
if (lockRecv)
|
||||
vRecvMsg.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,7 +638,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes)
|
||||
while (nBytes > 0) {
|
||||
|
||||
// get current incomplete message, or create a new one
|
||||
if (vRecvMsg.size() == 0 ||
|
||||
if (vRecvMsg.empty() ||
|
||||
vRecvMsg.back().complete())
|
||||
vRecvMsg.push_back(CNetMessage(SER_NETWORK, nRecvVersion));
|
||||
|
||||
@@ -1767,6 +1771,9 @@ void ThreadMessageHandler2(void* parg)
|
||||
pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())];
|
||||
BOOST_FOREACH(CNode* pnode, vNodesCopy)
|
||||
{
|
||||
if (pnode->fDisconnect)
|
||||
continue;
|
||||
|
||||
// Receive messages
|
||||
{
|
||||
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
|
||||
|
||||
Reference in New Issue
Block a user