From ef6ccef510e10893a11ae691857c5e9c4715e097 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Sat, 26 Oct 2024 15:36:49 +0100 Subject: [PATCH] Simplify code flow. Change-Id: Ifc18ae945f9946e511a394dd92d4e884e6d3ae6d Signed-off-by: Michael Meeks --- net/Socket.cpp | 58 +++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/net/Socket.cpp b/net/Socket.cpp index 3a1469dbc1186..c6206506b9eaf 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -1480,40 +1480,40 @@ std::ostream& StreamSocket::stream(std::ostream& os) const bool StreamSocket::checkRemoval(std::chrono::steady_clock::time_point now) { - if( isIPType() ) - { - // Forced removal on outside-facing IPv[46] network connections only - const auto durLast = - std::chrono::duration_cast(now - getLastSeenTime()); - /// TO Criteria: Violate maximum idle (_pollTimeout default 64s) - const bool isIdle = _pollTimeout > std::chrono::microseconds::zero() && - durLast > _pollTimeout; - /// TO Criteria: Shall terminate? - const bool isTermination = SigUtil::getTerminationFlag(); - if (isIdle || isTermination ) + if( !isIPType() ) + return false; + + // Forced removal on outside-facing IPv[46] network connections only + const auto durLast = + std::chrono::duration_cast(now - getLastSeenTime()); + /// TO Criteria: Violate maximum idle (_pollTimeout default 64s) + const bool isIdle = _pollTimeout > std::chrono::microseconds::zero() && + durLast > _pollTimeout; + /// TO Criteria: Shall terminate? + const bool isTermination = SigUtil::getTerminationFlag(); + if (isIdle || isTermination ) + { + LOG_WRN("CheckRemoval: Timeout: {Idle " << isIdle + << ", Termination " << isTermination << "}, " + << getStatsString(now) << ", " + << *this); + if (_socketHandler) { - LOG_WRN("CheckRemoval: Timeout: {Idle " << isIdle - << ", Termination " << isTermination << "}, " - << getStatsString(now) << ", " - << *this); - if (_socketHandler) - { - _socketHandler->onDisconnect(); - if( isOpen() ) { - // Note: Ensure proper semantics of onDisconnect() - LOG_WRN("Socket still open post onDisconnect(), forced shutdown."); - shutdown(); // signal - closeConnection(); // real -> setClosed() - } - } - else - { + _socketHandler->onDisconnect(); + if( isOpen() ) { + // Note: Ensure proper semantics of onDisconnect() + LOG_WRN("Socket still open post onDisconnect(), forced shutdown."); shutdown(); // signal closeConnection(); // real -> setClosed() } - assert(isOpen() == false); // should have issued shutdown - return true; } + else + { + shutdown(); // signal + closeConnection(); // real -> setClosed() + } + assert(isOpen() == false); // should have issued shutdown + return true; } return false; }