aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-03-01 01:41:28 +0100
committerPieter Wuille <sipa@ulyssis.org>2013-03-29 23:56:26 +0100
commit967f24590b43f0f84148f669d886b40fe45aa978 (patch)
tree5e0116b462a5433907d5400456d0006e14d332ee /src/net.cpp
parentb9ff2970b9fbb24e2fffc449b4ef478d019633d8 (diff)
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).
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp
index eafb335642..1016d5d9f0 100644
--- a/src/net.cpp
+++ b/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);