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

Function SocketSendData

src/net.cpp:667–718  ·  view source on GitHub ↗

requires LOCK(cs_vSend)

Source from the content-addressed store, hash-verified

665
666// requires LOCK(cs_vSend)
667void SocketSendData(CNode *pnode)
668{
669 std::deque<CSerializeData>::iterator it = pnode->vSendMsg.begin();
670
671 while (it != pnode->vSendMsg.end()) {
672 const CSerializeData &data = *it;
673 assert(data.size() > pnode->nSendOffset);
674
675 int amt2Send = min((int)(data.size() - pnode->nSendOffset),
676 sendShaper.available(SEND_SHAPER_MIN_FRAG));
677 if (amt2Send == 0) {
678 if (sendShaper.available(SEND_SHAPER_MIN_FRAG) != INT_MAX) //Sleep if traffic shaping is turned on
679 MilliSleep(10);
680 break;
681 }
682 int nBytes = send(pnode->hSocket, &data[pnode->nSendOffset], amt2Send, MSG_NOSIGNAL | MSG_DONTWAIT);
683 if (nBytes > 0) {
684 pnode->nLastSend = GetTime();
685 pnode->nSendBytes += nBytes;
686 pnode->nSendOffset += nBytes;
687 pnode->RecordBytesSent(nBytes);
688 bool empty = !sendShaper.consume(nBytes);
689 if (pnode->nSendOffset == data.size()) {
690 pnode->nSendOffset = 0;
691 pnode->nSendSize -= data.size();
692 it++;
693 } else {
694 // could not send full message; stop sending more
695 break;
696 }
697 if (empty) break; // Exceeded our send budget, stop sending more
698 } else {
699 if (nBytes < 0) {
700 // error
701 int nErr = WSAGetLastError();
702 if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
703 {
704 LogPrintf("socket send error %s\n", NetworkErrorString(nErr));
705 pnode->CloseSocketDisconnect();
706 }
707 }
708 // couldn't send anything at all
709 break;
710 }
711 }
712
713 if (it == pnode->vSendMsg.end()) {
714 assert(pnode->nSendOffset == 0);
715 assert(pnode->nSendSize == 0);
716 }
717 pnode->vSendMsg.erase(pnode->vSendMsg.begin(), it);
718}
719
720static list<CNode*> vNodesDisconnected;
721

Callers 2

BOOST_FOREACHFunction · 0.85
UNLOCK_FUNCTIONFunction · 0.85

Calls 11

MilliSleepFunction · 0.85
GetTimeFunction · 0.85
NetworkErrorStringFunction · 0.85
availableMethod · 0.80
RecordBytesSentMethod · 0.80
consumeMethod · 0.80
CloseSocketDisconnectMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected