From 3d1402fbb6437d2b4bc3450b3e3362ddbb2df325 Mon Sep 17 00:00:00 2001 From: Jonas van den Berg Date: Thu, 12 Sep 2024 13:25:42 +0200 Subject: [PATCH] Attempt to reconnect immediately with Qt There's no reason to wait immediately after a disconnect --- client/src/websocket/backend_qt.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/websocket/backend_qt.cpp b/client/src/websocket/backend_qt.cpp index 4168410..b97d27e 100644 --- a/client/src/websocket/backend_qt.cpp +++ b/client/src/websocket/backend_qt.cpp @@ -104,7 +104,13 @@ std::chrono::milliseconds ClientImpl::next_reconnect_delay() { using namespace std::chrono_literals; - if (m_reconnect_count > 0 && options().max_reconnect_delay.has_value()) { + auto count = m_reconnect_count; + m_reconnect_count += 1; + + if (count == 0) { + return 0ms; // Attempt to reconnect immediately. + } + if (count > 1 && options().max_reconnect_delay.has_value()) { // Exponentially increase reconnect delay. auto next = std::min( options().max_reconnect_delay.value(), 2 * m_reconnect_delay); @@ -113,7 +119,6 @@ std::chrono::milliseconds ClientImpl::next_reconnect_delay() next = std::max(options().reconnect_delay.value(), next); m_reconnect_delay = next; } - m_reconnect_count += 1; return m_reconnect_delay; }