requires LOCK(cs_vSend)
| 665 | |
| 666 | // requires LOCK(cs_vSend) |
| 667 | void 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 | |
| 720 | static list<CNode*> vNodesDisconnected; |
| 721 |
no test coverage detected