From 8f60b0e6bf50b44d5cc6587b8ddcccc4d2a8e78c Mon Sep 17 00:00:00 2001 From: Fletcher Dunn Date: Sat, 30 May 2020 13:40:39 -0700 Subject: [PATCH] Fix inverted logic Revert part of 705bc0e4bbbb891cf797dfb8e5595efaefeb1e31, which managed to refactor code without improving it in any way AND introduce an inverted logic bug. This causes us to spam panic keepalives when we are timing out much faster than intended. Also, when deciding if it is time to take action, use inclusive comparisons. If we ask to wake up at a certain time, and we do actually manage to wake up at that exact time, then we should take action. This is probably extremely rare, however in an environment with limited timer precision, it could be more common. --- src/steamnetworkingsockets/steamnetworking_statsutils.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/steamnetworkingsockets/steamnetworking_statsutils.h b/src/steamnetworkingsockets/steamnetworking_statsutils.h index a9bf41f..091003f 100644 --- a/src/steamnetworkingsockets/steamnetworking_statsutils.h +++ b/src/steamnetworkingsockets/steamnetworking_statsutils.h @@ -579,9 +579,10 @@ struct LinkStatsTrackerBase /// connectivity as well. inline bool BNeedToSendPingImmediate( SteamNetworkingMicroseconds usecNow ) const { - if ( m_bPassive || m_nReplyTimeoutsSinceLastRecv == 0 ) - return false; - return usecNow < m_usecLastSendPacketExpectingImmediateReply+k_usecAggressivePingInterval; + return + !m_bPassive + && m_nReplyTimeoutsSinceLastRecv > 0 // We're timing out + && m_usecLastSendPacketExpectingImmediateReply+k_usecAggressivePingInterval <= usecNow; // we haven't just recently sent an aggressive ping. } /// Check if we should send a keepalive ping. In this case we haven't heard from the peer in a while, @@ -591,7 +592,7 @@ struct LinkStatsTrackerBase return !m_bPassive && m_usecInFlightReplyTimeout == 0 // not already tracking some other message for which we expect a reply (and which would confirm that the connection is alive) - && m_usecTimeLastRecv + k_usecKeepAliveInterval < usecNow; // haven't heard from the peer recently + && m_usecTimeLastRecv + k_usecKeepAliveInterval <= usecNow; // haven't heard from the peer recently } /// Fill out message with everything we'd like to send. We don't assume that we will