From a6571e2d8a02d93e817465fcd44d0acb642569a8 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Fri, 29 Apr 2022 12:29:45 +0200 Subject: [PATCH] improve readability of computation of currentDelay recoonect time Signed-off-by: Matthieu Gallien --- src/gui/accountstate.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index c86efc11a..8b342427d 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -525,10 +525,11 @@ void AccountState::slotOcsError(int statusCode, const QString &message) void AccountState::slotCheckConnection() { if (_lastCheckConnectionTimer.isValid()) { - const auto currentDelay = (retryCount() <= 1 ? ConnectionValidator::DefaultCallingIntervalMsec : - (retryCount() == 2 ? ConnectionValidator::DefaultCallingIntervalMsec * 2 : - (retryCount() == 3 ? ConnectionValidator::DefaultCallingIntervalMsec * 4 : - ConnectionValidator::DefaultCallingIntervalMsec * 8))); + static constexpr auto DefaultCallingIntervalMaxMsec = static_cast(ConnectionValidator::DefaultCallingIntervalMsec) * 8; + + const auto minDelay = std::max(retryCount() * ConnectionValidator::DefaultCallingIntervalMsec, + static_cast(ConnectionValidator::DefaultCallingIntervalMsec)); + const auto currentDelay = std::min(minDelay, DefaultCallingIntervalMaxMsec); if (!_lastCheckConnectionTimer.hasExpired(currentDelay - 1)) { qCInfo(lcAccountState()) << "timer has not expired: do not check now" << _lastCheckConnectionTimer.elapsed() << currentDelay; -- 2.30.2