Chatterino
IrcConnection2.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <pajlada/signals/signal.hpp>
6 
7 #include <IrcConnection>
8 #include <QTimer>
9 
10 namespace chatterino {
11 
12 class IrcConnection : public Communi::IrcConnection
13 {
14 public:
15  IrcConnection(QObject *parent = nullptr);
16  ~IrcConnection() override;
17 
18  // Signal to notify that we're unexpectedly no longer connected, either due
19  // to a connection error or if we think we've timed out. It's up to the
20  // receiver to trigger a reconnect, if desired
21  pajlada::Signals::Signal<bool> connectionLost;
22 
23  // Request a reconnect with a minimum interval between attempts.
24  pajlada::Signals::NoArgSignal smartReconnect;
25 
26  virtual void open();
27  virtual void close();
28 
29 private:
30  QTimer pingTimer_;
31  QTimer reconnectTimer_;
32  std::atomic<bool> recentlyReceivedMessage_{true};
33 
34  // Reconnect with a base delay of 1 second and max out at 1 second * (2^(5-1)) (i.e. 16 seconds)
35  ExponentialBackoff<5> reconnectBackoff_{std::chrono::milliseconds{1000}};
36 
37  std::atomic<bool> expectConnectionLoss_{false};
38 
39  // waitingForPong_ is set to true when we send a PING message, and back to
40  // false when we receive the matching PONG response
41  std::atomic<bool> waitingForPong_{false};
42 };
43 
44 } // namespace chatterino
Definition: Application.cpp:48
pajlada::Signals::Signal< bool > connectionLost
Definition: IrcConnection2.hpp:21
pajlada::Signals::NoArgSignal smartReconnect
Definition: IrcConnection2.hpp:24
virtual void close()
Definition: IrcConnection2.cpp:134
Definition: IrcConnection2.hpp:12
virtual void open()
Definition: IrcConnection2.cpp:126
~IrcConnection() override
Definition: IrcConnection2.cpp:120
IrcConnection(QObject *parent=nullptr)
Definition: IrcConnection2.cpp:14