Use an exponential backoff when deciding how long we need to wait for reconnects (#2892)

Co-authored-by: Leon Richardt <leon.richardt@gmail.com>
This commit is contained in:
pajlada
2021-06-20 15:29:52 +02:00
committed by GitHub
parent d6b5921a0e
commit 0c2488505c
6 changed files with 129 additions and 18 deletions
+5 -2
View File
@@ -1,10 +1,11 @@
#pragma once
#include "util/ExponentialBackoff.hpp"
#include <pajlada/signals/signal.hpp>
#include <IrcConnection>
#include <QTimer>
#include <chrono>
namespace chatterino {
@@ -28,7 +29,9 @@ private:
QTimer pingTimer_;
QTimer reconnectTimer_;
std::atomic<bool> recentlyReceivedMessage_{true};
std::chrono::steady_clock::time_point lastConnected_;
// Reconnect with a base delay of 1 second and max out at 1 second * (2^4) (i.e. 16 seconds)
ExponentialBackoff<4> reconnectBackoff_{std::chrono::milliseconds{1000}};
std::atomic<bool> expectConnectionLoss_{false};