Skip to content

Commit 60befa3

Browse files
committed
net: handle message accounting in ReceiveMsgBytes
This allows locking to be pushed down to only where it's needed Also reuse the current time rather than checking multiple times.
1 parent 56212e2 commit 60befa3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/net.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ void CNode::copyStats(CNodeStats &stats)
648648
bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete)
649649
{
650650
complete = false;
651+
int64_t nTimeMicros = GetTimeMicros();
652+
nLastRecv = nTimeMicros / 1000000;
653+
nRecvBytes += nBytes;
651654
while (nBytes > 0) {
652655

653656
// get current incomplete message, or create a new one
@@ -685,7 +688,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete
685688
assert(i != mapRecvBytesPerMsgCmd.end());
686689
i->second += msg.hdr.nMessageSize + CMessageHeader::HEADER_SIZE;
687690

688-
msg.nTime = GetTimeMicros();
691+
msg.nTime = nTimeMicros;
689692
complete = true;
690693
}
691694
}
@@ -1237,8 +1240,6 @@ void CConnman::ThreadSocketHandler()
12371240
pnode->CloseSocketDisconnect();
12381241
if(notify)
12391242
condMsgProc.notify_one();
1240-
pnode->nLastRecv = GetTime();
1241-
pnode->nRecvBytes += nBytes;
12421243
RecordBytesRecv(nBytes);
12431244
}
12441245
else if (nBytes == 0)

0 commit comments

Comments
 (0)