MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / SocketSendData

Method SocketSendData

src/p2p/node.cpp:61–101  ·  view source on GitHub ↗

requires LOCK(cs_vSend)

Source from the content-addressed store, hash-verified

59
60// requires LOCK(cs_vSend)
61void CNode::SocketSendData() {
62 deque<CSerializeData>::iterator it = vSendMsg.begin();
63
64 while (it != vSendMsg.end()) {
65 const CSerializeData& data = *it;
66 assert(data.size() > nSendOffset);
67 int32_t nBytes = send(hSocket, &data[nSendOffset], data.size() - nSendOffset,
68 MSG_NOSIGNAL | MSG_DONTWAIT);
69 if (nBytes > 0) {
70 nLastSend = GetTime();
71 nSendBytes += nBytes;
72 nSendOffset += nBytes;
73 RecordBytesSent(nBytes);
74 if (nSendOffset == data.size()) {
75 nSendOffset = 0;
76 nSendSize -= data.size();
77 it++;
78 } else {
79 // could not send full message; stop sending more
80 break;
81 }
82 } else {
83 if (nBytes < 0) {
84 // error
85 int32_t nErr = WSAGetLastError();
86 if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS) {
87 LogPrint(BCLog::INFO, "socket send error %s\n", NetworkErrorString(nErr));
88 CloseSocketDisconnect();
89 }
90 }
91 // couldn't send anything at all
92 break;
93 }
94 }
95
96 if (it == vSendMsg.end()) {
97 assert(nSendOffset == 0);
98 assert(nSendSize == 0);
99 }
100 vSendMsg.erase(vSendMsg.begin(), it);
101}
102
103
104

Callers 1

ThreadSocketHandlerFunction · 0.80

Calls 6

GetTimeFunction · 0.85
NetworkErrorStringFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected