Try to improve Twitch IRC network stability (#2347)

This commit is contained in:
pajlada
2021-01-09 18:05:02 +01:00
committed by GitHub
parent d0deb44abf
commit b3e01a40d7
5 changed files with 49 additions and 8 deletions
+21
View File
@@ -62,6 +62,8 @@ AbstractIrcServer::AbstractIrcServer()
// listen to reconnect request
this->readConnection_->reconnectRequested.connect([this] {
this->addGlobalSystemMessage(
"Server connection timed out, reconnecting");
this->connect();
});
// this->writeConnection->reconnectRequested.connect([this] {
@@ -135,6 +137,25 @@ void AbstractIrcServer::open(ConnectionType type)
}
}
void AbstractIrcServer::addGlobalSystemMessage(QString messageText)
{
std::lock_guard<std::mutex> lock(this->channelMutex);
MessageBuilder b(systemMessage, messageText);
auto message = b.release();
for (std::weak_ptr<Channel> &weak : this->channels.values())
{
std::shared_ptr<Channel> chan = weak.lock();
if (!chan)
{
continue;
}
chan->addMessage(message);
}
}
void AbstractIrcServer::disconnect()
{
std::lock_guard<std::mutex> locker(this->connectionMutex_);
+2
View File
@@ -78,6 +78,8 @@ protected:
void open(ConnectionType type);
void addGlobalSystemMessage(QString messageText);
QMap<QString, std::weak_ptr<Channel>> channels;
std::mutex channelMutex;
+13 -8
View File
@@ -57,15 +57,20 @@ IrcConnection::IrcConnection(QObject *parent)
}
});
QObject::connect(this, &Communi::IrcConnection::messageReceived,
[this](Communi::IrcMessage *) {
this->recentlyReceivedMessage_ = true;
QObject::connect(
this, &Communi::IrcConnection::messageReceived,
[this](Communi::IrcMessage *message) {
this->recentlyReceivedMessage_ = true;
if (this->reconnectTimer_.isActive())
{
this->reconnectTimer_.stop();
}
});
if (this->reconnectTimer_.isActive())
{
this->reconnectTimer_.stop();
// The reconnect timer had started, that means we were waiting for a pong.
// Since we received a message, this means that any pong response is meaningless, so we can just stop waiting for the pong and send another ping soon:tm:
this->waitingForPong_ = false;
}
});
}
} // namespace chatterino
+12
View File
@@ -165,6 +165,12 @@ void TwitchIrcServer::readConnectionMessageReceived(
{
handler.handleWhisperMessage(message);
}
else if (command == "RECONNECT")
{
this->addGlobalSystemMessage(
"Twitch Servers requested us to reconnect, reconnecting");
this->connect();
}
}
void TwitchIrcServer::writeConnectionMessageReceived(
@@ -207,6 +213,12 @@ void TwitchIrcServer::writeConnectionMessageReceived(
handler.handleNoticeMessage(
static_cast<Communi::IrcNoticeMessage *>(message));
}
else if (command == "RECONNECT")
{
this->addGlobalSystemMessage(
"Twitch Servers requested us to reconnect, reconnecting");
this->connect();
}
}
void TwitchIrcServer::onReadConnected(IrcConnection *connection)