diff options
author | Jeff Garzik <jgarzik@exmulti.com> | 2012-11-15 18:04:52 -0500 |
---|---|---|
committer | Pieter Wuille <sipa@ulyssis.org> | 2013-03-29 23:56:25 +0100 |
commit | bc2f5aa72cfb3f456280a6d34c5d425bf24b009c (patch) | |
tree | 513ed640d79d1062dc3d710f00e7e7a1beb6e3ac /src | |
parent | 607dbfdeaf7ec053d959c47c125d60c0b7e7216a (diff) |
P2P, cosmetic: break out buffer send(2) code into separate function
Diffstat (limited to 'src')
-rw-r--r-- | src/net.cpp | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/net.cpp b/src/net.cpp index 0e558228d7..96719367ce 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -708,6 +708,30 @@ int CNetMessage::readData(const char *pch, unsigned int nBytes) +// requires LOCK(cs_vSend) +void SocketSendData(CNode *pnode) +{ + CDataStream& vSend = pnode->vSend; + if (vSend.empty()) + return; + + int nBytes = send(pnode->hSocket, &vSend[0], vSend.size(), MSG_NOSIGNAL | MSG_DONTWAIT); + if (nBytes > 0) + { + vSend.erase(vSend.begin(), vSend.begin() + nBytes); + pnode->nLastSend = GetTime(); + } + else if (nBytes < 0) + { + // error + int nErr = WSAGetLastError(); + if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS) + { + printf("socket send error %d\n", nErr); + pnode->CloseSocketDisconnect(); + } + } +} void ThreadSocketHandler(void* parg) { @@ -994,28 +1018,7 @@ void ThreadSocketHandler2(void* parg) { TRY_LOCK(pnode->cs_vSend, lockSend); if (lockSend) - { - CDataStream& vSend = pnode->vSend; - if (!vSend.empty()) - { - int nBytes = send(pnode->hSocket, &vSend[0], vSend.size(), MSG_NOSIGNAL | MSG_DONTWAIT); - if (nBytes > 0) - { - vSend.erase(vSend.begin(), vSend.begin() + nBytes); - pnode->nLastSend = GetTime(); - } - else if (nBytes < 0) - { - // error - int nErr = WSAGetLastError(); - if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS) - { - printf("socket send error %d\n", nErr); - pnode->CloseSocketDisconnect(); - } - } - } - } + SocketSendData(pnode); } // |