1
0

Do an early check for empty network buffers (#5172)

Avoid overhead when nothing to do.
This commit is contained in:
Tiger Wang 2021-03-29 23:36:00 +01:00 committed by GitHub
parent abcc14076c
commit 8ec5552998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -232,6 +232,13 @@ void cClientHandle::ProcessProtocolOut()
decltype(m_OutgoingData) OutgoingData; decltype(m_OutgoingData) OutgoingData;
{ {
cCSLock Lock(m_CSOutgoingData); 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); std::swap(OutgoingData, m_OutgoingData);
} }
@ -3318,14 +3325,16 @@ void cClientHandle::ProcessProtocolIn(void)
decltype(m_IncomingData) IncomingData; decltype(m_IncomingData) IncomingData;
{ {
cCSLock Lock(m_CSIncomingData); cCSLock Lock(m_CSIncomingData);
std::swap(IncomingData, m_IncomingData);
}
if (IncomingData.empty()) // Bail out when nothing was received:
if (m_IncomingData.empty())
{ {
return; return;
} }
std::swap(IncomingData, m_IncomingData);
}
try try
{ {
m_Protocol.HandleIncomingData(*this, std::move(IncomingData)); m_Protocol.HandleIncomingData(*this, std::move(IncomingData));