Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 770 Lines • ▼ Show 20 Lines | |||||
const uint256 &CNetMessage::GetMessageHash() const { | const uint256 &CNetMessage::GetMessageHash() const { | ||||
assert(complete()); | assert(complete()); | ||||
if (data_hash.IsNull()) hasher.Finalize(data_hash.begin()); | if (data_hash.IsNull()) hasher.Finalize(data_hash.begin()); | ||||
return data_hash; | return data_hash; | ||||
} | } | ||||
// requires LOCK(cs_vSend) | // requires LOCK(cs_vSend) | ||||
size_t CConnman::SocketSendData(CNode *pnode) const { | size_t CConnman::SocketSendData(CNode *pnode) const { | ||||
auto it = pnode->vSendMsg.begin(); | AssertLockHeld(pnode->cs_vSend); | ||||
size_t nSentSize = 0; | size_t nSentSize = 0; | ||||
size_t nMsgCount = 0; | |||||
while (it != pnode->vSendMsg.end()) { | for (const auto &data : pnode->vSendMsg) { | ||||
const auto &data = *it; | |||||
assert(data.size() > pnode->nSendOffset); | assert(data.size() > pnode->nSendOffset); | ||||
int nBytes = 0; | int nBytes = 0; | ||||
{ | { | ||||
LOCK(pnode->cs_hSocket); | LOCK(pnode->cs_hSocket); | ||||
if (pnode->hSocket == INVALID_SOCKET) break; | if (pnode->hSocket == INVALID_SOCKET) break; | ||||
nBytes = send( | nBytes = send( | ||||
pnode->hSocket, reinterpret_cast<const char *>(data.data()) + | pnode->hSocket, reinterpret_cast<const char *>(data.data()) + | ||||
pnode->nSendOffset, | pnode->nSendOffset, | ||||
data.size() - pnode->nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT); | data.size() - pnode->nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT); | ||||
} | } | ||||
if (nBytes > 0) { | |||||
pnode->nLastSend = GetSystemTimeInSeconds(); | if (nBytes == 0) { | ||||
pnode->nSendBytes += nBytes; | // couldn't send anything at all | ||||
pnode->nSendOffset += nBytes; | |||||
nSentSize += nBytes; | |||||
if (pnode->nSendOffset == data.size()) { | |||||
pnode->nSendOffset = 0; | |||||
pnode->nSendSize -= data.size(); | |||||
pnode->fPauseSend = pnode->nSendSize > nSendBufferMaxSize; | |||||
it++; | |||||
} else { | |||||
// could not send full message; stop sending more | |||||
break; | break; | ||||
} | } | ||||
} else { | |||||
if (nBytes < 0) { | if (nBytes < 0) { | ||||
// error | // error | ||||
int nErr = WSAGetLastError(); | int nErr = WSAGetLastError(); | ||||
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && | if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && | ||||
nErr != WSAEINTR && nErr != WSAEINPROGRESS) { | nErr != WSAEINTR && nErr != WSAEINPROGRESS) { | ||||
LogPrintf("socket send error %s\n", | LogPrintf("socket send error %s\n", NetworkErrorString(nErr)); | ||||
NetworkErrorString(nErr)); | |||||
pnode->CloseSocketDisconnect(); | pnode->CloseSocketDisconnect(); | ||||
} | } | ||||
break; | |||||
} | } | ||||
// couldn't send anything at all | |||||
assert(nBytes > 0); | |||||
pnode->nLastSend = GetSystemTimeInSeconds(); | |||||
pnode->nSendBytes += nBytes; | |||||
pnode->nSendOffset += nBytes; | |||||
nSentSize += nBytes; | |||||
if (pnode->nSendOffset != data.size()) { | |||||
// could not send full message; stop sending more | |||||
break; | break; | ||||
} | } | ||||
pnode->nSendOffset = 0; | |||||
pnode->nSendSize -= data.size(); | |||||
pnode->fPauseSend = pnode->nSendSize > nSendBufferMaxSize; | |||||
nMsgCount++; | |||||
} | } | ||||
if (it == pnode->vSendMsg.end()) { | pnode->vSendMsg.erase(pnode->vSendMsg.begin(), | ||||
pnode->vSendMsg.begin() + nMsgCount); | |||||
if (pnode->vSendMsg.empty()) { | |||||
assert(pnode->nSendOffset == 0); | assert(pnode->nSendOffset == 0); | ||||
assert(pnode->nSendSize == 0); | assert(pnode->nSendSize == 0); | ||||
} | } | ||||
pnode->vSendMsg.erase(pnode->vSendMsg.begin(), it); | |||||
return nSentSize; | return nSentSize; | ||||
} | } | ||||
struct NodeEvictionCandidate { | struct NodeEvictionCandidate { | ||||
NodeId id; | NodeId id; | ||||
int64_t nTimeConnected; | int64_t nTimeConnected; | ||||
int64_t nMinPingUsecTime; | int64_t nMinPingUsecTime; | ||||
int64_t nLastBlockTime; | int64_t nLastBlockTime; | ||||
▲ Show 20 Lines • Show All 1,992 Lines • Show Last 20 Lines |