requires LOCK(cs_vSend)
| 59 | |
| 60 | // requires LOCK(cs_vSend) |
| 61 | void 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 |
no test coverage detected