From ee44fa95761724a83a76dd862a36bd9af0fc021f Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Mon, 18 Apr 2016 21:33:54 -0400 Subject: [PATCH] net: move messageHandlerCondition to CConnman --- src/net.cpp | 11 +++++++---- src/net.h | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 71b4b0168..a62ee2291 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -89,7 +89,6 @@ std::string strSubVersion; limitedmap mapAlreadyAskedFor(MAX_INV_SZ); static CSemaphore *semOutbound = NULL; -boost::condition_variable messageHandlerCondition; // Signals for message handling static CNodeSignals g_signals; @@ -688,8 +687,9 @@ void CNode::copyStats(CNodeStats &stats) #undef X // requires LOCK(cs_vRecvMsg) -bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes) +bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete) { + complete = false; while (nBytes > 0) { // get current incomplete message, or create a new one @@ -728,7 +728,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes) i->second += msg.hdr.nMessageSize + CMessageHeader::HEADER_SIZE; msg.nTime = GetTimeMicros(); - messageHandlerCondition.notify_one(); + complete = true; } } @@ -1247,8 +1247,11 @@ void CConnman::ThreadSocketHandler() int nBytes = recv(pnode->hSocket, pchBuf, sizeof(pchBuf), MSG_DONTWAIT); if (nBytes > 0) { - if (!pnode->ReceiveMsgBytes(pchBuf, nBytes)) + bool notify = false; + if (!pnode->ReceiveMsgBytes(pchBuf, nBytes, notify)) pnode->CloseSocketDisconnect(); + if(notify) + messageHandlerCondition.notify_one(); pnode->nLastRecv = GetTime(); pnode->nRecvBytes += nBytes; pnode->RecordBytesRecv(nBytes); diff --git a/src/net.h b/src/net.h index 32668045c..0e83ff4a0 100644 --- a/src/net.h +++ b/src/net.h @@ -228,6 +228,7 @@ private: std::vector vNodes; mutable CCriticalSection cs_vNodes; std::atomic nLastNodeId; + boost::condition_variable messageHandlerCondition; }; extern std::unique_ptr g_connman; void MapPort(bool fUseUPnP); @@ -550,7 +551,7 @@ public: } // requires LOCK(cs_vRecvMsg) - bool ReceiveMsgBytes(const char *pch, unsigned int nBytes); + bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete); // requires LOCK(cs_vRecvMsg) void SetRecvVersion(int nVersionIn)