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

Method SocketSendData

src/net.cpp:885–935  ·  view source on GitHub ↗

requires LOCK(cs_vSend)

Source from the content-addressed store, hash-verified

883
884// requires LOCK(cs_vSend)
885size_t CConnman::SocketSendData(CNode *pnode) const
886{
887 auto it = pnode->vSendMsg.begin();
888 size_t nSentSize = 0;
889
890 while (it != pnode->vSendMsg.end()) {
891 const auto &data = *it;
892 assert(data.size() > pnode->nSendOffset);
893 int nBytes = 0;
894 {
895 LOCK(pnode->cs_hSocket);
896 if (pnode->hSocket == INVALID_SOCKET)
897 break;
898 nBytes = send(pnode->hSocket, reinterpret_cast<const char*>(data.data()) + pnode->nSendOffset, data.size() - pnode->nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT);
899 }
900 if (nBytes > 0) {
901 pnode->nLastSend = GetSystemTimeInSeconds();
902 pnode->nSendBytes += nBytes;
903 pnode->nSendOffset += nBytes;
904 nSentSize += nBytes;
905 if (pnode->nSendOffset == data.size()) {
906 pnode->nSendOffset = 0;
907 pnode->nSendSize -= data.size();
908 pnode->fPauseSend = pnode->nSendSize > nSendBufferMaxSize;
909 it++;
910 } else {
911 // could not send full message; stop sending more
912 break;
913 }
914 } else {
915 if (nBytes < 0) {
916 // error
917 int nErr = WSAGetLastError();
918 if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
919 {
920 LogPrintf("socket send error %s\n", NetworkErrorString(nErr));
921 pnode->CloseSocketDisconnect();
922 }
923 }
924 // couldn't send anything at all
925 break;
926 }
927 }
928
929 if (it == pnode->vSendMsg.end()) {
930 assert(pnode->nSendOffset == 0);
931 assert(pnode->nSendSize == 0);
932 }
933 pnode->vSendMsg.erase(pnode->vSendMsg.begin(), it);
934 return nSentSize;
935}
936
937struct NodeEvictionCandidate
938{

Callers

nothing calls this directly

Calls 8

GetSystemTimeInSecondsFunction · 0.85
NetworkErrorStringFunction · 0.85
CloseSocketDisconnectMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected