diff --git a/src/net.cpp b/src/net.cpp index 71843e8ded019..008f57b953630 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1879,11 +1879,9 @@ void CConnman::SocketHandler() break; } - LOCK(pnode->cs_vSend); - size_t nBytes = SocketSendData(pnode); - if (nBytes) { - RecordBytesSent(nBytes); - } + // Send data + size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(pnode)); + if (bytes_sent) RecordBytesSent(bytes_sent); } ReleaseNodeVector(vErrorNodes); diff --git a/src/net.h b/src/net.h index 359c00b795a99..37ec65c801c6e 100644 --- a/src/net.h +++ b/src/net.h @@ -1030,8 +1030,10 @@ class CNode NetPermissionFlags m_permissionFlags{ PF_NONE }; std::atomic nServices{NODE_NONE}; SOCKET hSocket GUARDED_BY(cs_hSocket); - size_t nSendSize{0}; // total size of all vSendMsg entries - size_t nSendOffset{0}; // offset inside the first vSendMsg already sent + /** Total size of all vSendMsg entries */ + size_t nSendSize GUARDED_BY(cs_vSend){0}; + /** Offset inside the first vSendMsg already sent */ + size_t nSendOffset GUARDED_BY(cs_vSend){0}; uint64_t nSendBytes GUARDED_BY(cs_vSend){0}; std::list> vSendMsg GUARDED_BY(cs_vSend); std::atomic nSendMsgSize{0}; @@ -1123,7 +1125,7 @@ class CNode Network ConnectedThroughNetwork() const; protected: - mapMsgCmdSize mapSendBytesPerMsgCmd; + mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend); mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv); public: