From 8ec555299873712d03c76f705e5bfe7ade01da4d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 29 Mar 2021 23:36:00 +0100 Subject: Do an early check for empty network buffers (#5172) Avoid overhead when nothing to do. --- src/ClientHandle.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 04436070c..5762de897 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -232,6 +232,13 @@ void cClientHandle::ProcessProtocolOut() decltype(m_OutgoingData) OutgoingData; { cCSLock Lock(m_CSOutgoingData); + + // Bail out when there's nothing to send to avoid TCPLink::Send overhead: + if (m_OutgoingData.empty()) + { + return; + } + std::swap(OutgoingData, m_OutgoingData); } @@ -3318,12 +3325,14 @@ void cClientHandle::ProcessProtocolIn(void) decltype(m_IncomingData) IncomingData; { cCSLock Lock(m_CSIncomingData); - std::swap(IncomingData, m_IncomingData); - } - if (IncomingData.empty()) - { - return; + // Bail out when nothing was received: + if (m_IncomingData.empty()) + { + return; + } + + std::swap(IncomingData, m_IncomingData); } try -- cgit v1.2.3