added code to handle a single connection

This commit is contained in:
fourtf
2018-07-16 17:23:41 +02:00
parent e51c5c692a
commit 3b3c5d8d75
18 changed files with 114 additions and 84 deletions
+11 -6
View File
@@ -9,18 +9,23 @@ IrcConnection::IrcConnection(QObject *parent)
this->pingTimer_.setInterval(5000);
this->pingTimer_.start();
QObject::connect(&this->pingTimer_, &QTimer::timeout, [this] {
if (!this->recentlyReceivedMessage_.load()) {
this->sendRaw("PING");
this->reconnectTimer_.start();
if (this->isConnected()) {
if (!this->recentlyReceivedMessage_.load()) {
this->sendRaw("PING");
this->reconnectTimer_.start();
}
this->recentlyReceivedMessage_ = false;
}
this->recentlyReceivedMessage_ = false;
});
// reconnect after x seconds without receiving a message
this->reconnectTimer_.setInterval(5000);
this->reconnectTimer_.setSingleShot(true);
QObject::connect(&this->reconnectTimer_, &QTimer::timeout,
[this] { reconnectRequested.invoke(); });
QObject::connect(&this->reconnectTimer_, &QTimer::timeout, [this] {
if (this->isConnected()) {
reconnectRequested.invoke();
}
});
QObject::connect(this, &Communi::IrcConnection::messageReceived, [this](Communi::IrcMessage *) {
this->recentlyReceivedMessage_ = true;