merge bitcoin#20864: Move SocketSendData lock annotation to header

includes:
- fa210689e27b0d78b2fe894e51e364179db7a3ce
This commit is contained in:
Kittywhiskers Van Gogh 2024-03-19 18:41:58 +00:00
parent e432122cbd
commit 140e91fdca
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
2 changed files with 27 additions and 27 deletions

View File

@ -876,34 +876,34 @@ void V1TransportSerializer::prepareForTransport(CSerializedNetMsg& msg, std::vec
CVectorWriter{SER_NETWORK, INIT_PROTO_VERSION, header, 0, hdr}; CVectorWriter{SER_NETWORK, INIT_PROTO_VERSION, header, 0, hdr};
} }
size_t CConnman::SocketSendData(CNode *pnode) EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_vSend) size_t CConnman::SocketSendData(CNode& node)
{ {
auto it = pnode->vSendMsg.begin(); auto it = node.vSendMsg.begin();
size_t nSentSize = 0; size_t nSentSize = 0;
while (it != pnode->vSendMsg.end()) { while (it != node.vSendMsg.end()) {
const auto &data = *it; const auto& data = *it;
assert(data.size() > pnode->nSendOffset); assert(data.size() > node.nSendOffset);
int nBytes = 0; int nBytes = 0;
{ {
LOCK(pnode->cs_hSocket); LOCK(node.cs_hSocket);
if (pnode->hSocket == INVALID_SOCKET) if (node.hSocket == INVALID_SOCKET)
break; break;
nBytes = send(pnode->hSocket, reinterpret_cast<const char*>(data.data()) + pnode->nSendOffset, data.size() - pnode->nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT); nBytes = send(node.hSocket, reinterpret_cast<const char*>(data.data()) + node.nSendOffset, data.size() - node.nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT);
} }
if (nBytes > 0) { if (nBytes > 0) {
pnode->nLastSend = GetSystemTimeInSeconds(); node.nLastSend = GetSystemTimeInSeconds();
pnode->nSendBytes += nBytes; node.nSendBytes += nBytes;
pnode->nSendOffset += nBytes; node.nSendOffset += nBytes;
nSentSize += nBytes; nSentSize += nBytes;
if (pnode->nSendOffset == data.size()) { if (node.nSendOffset == data.size()) {
pnode->nSendOffset = 0; node.nSendOffset = 0;
pnode->nSendSize -= data.size(); node.nSendSize -= data.size();
pnode->fPauseSend = pnode->nSendSize > nSendBufferMaxSize; node.fPauseSend = node.nSendSize > nSendBufferMaxSize;
it++; it++;
} else { } else {
// could not send full message; stop sending more // could not send full message; stop sending more
pnode->fCanSendData = false; node.fCanSendData = false;
break; break;
} }
} else { } else {
@ -912,22 +912,22 @@ size_t CConnman::SocketSendData(CNode *pnode) EXCLUSIVE_LOCKS_REQUIRED(pnode->cs
int nErr = WSAGetLastError(); int nErr = WSAGetLastError();
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS) if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
{ {
LogPrintf("socket send error %s (peer=%d)\n", NetworkErrorString(nErr), pnode->GetId()); LogPrintf("socket send error %s (peer=%d)\n", NetworkErrorString(nErr), node.GetId());
pnode->fDisconnect = true; node.fDisconnect = true;
} }
} }
// couldn't send anything at all // couldn't send anything at all
pnode->fCanSendData = false; node.fCanSendData = false;
break; break;
} }
} }
if (it == pnode->vSendMsg.end()) { if (it == node.vSendMsg.end()) {
assert(pnode->nSendOffset == 0); assert(node.nSendOffset == 0);
assert(pnode->nSendSize == 0); assert(node.nSendSize == 0);
} }
pnode->vSendMsg.erase(pnode->vSendMsg.begin(), it); node.vSendMsg.erase(node.vSendMsg.begin(), it);
pnode->nSendMsgSize = pnode->vSendMsg.size(); node.nSendMsgSize = node.vSendMsg.size();
return nSentSize; return nSentSize;
} }
@ -1940,7 +1940,7 @@ void CConnman::SocketHandler()
} }
// Send data // Send data
size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(pnode)); size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(*pnode));
if (bytes_sent) RecordBytesSent(bytes_sent); if (bytes_sent) RecordBytesSent(bytes_sent);
} }

View File

@ -920,7 +920,7 @@ public:
* @param[in] pnode The node which we are sending messages to. * @param[in] pnode The node which we are sending messages to.
* @return True if there is more work to be done * @return True if there is more work to be done
*/ */
virtual bool SendMessages(CNode* pnode) = 0; virtual bool SendMessages(CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_sendProcessing) = 0;
protected: protected:
@ -1377,7 +1377,7 @@ private:
NodeId GetNewNodeId(); NodeId GetNewNodeId();
size_t SocketSendData(CNode *pnode); size_t SocketSendData(CNode& node) EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);
size_t SocketRecvData(CNode* pnode); size_t SocketRecvData(CNode* pnode);
void DumpAddresses(); void DumpAddresses();