From 0862c4b717c91b89b1754335aed8686ce68dfc52 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Sat, 1 May 2021 19:06:37 -0500 Subject: [PATCH] Add disconnect handling - Server will now attempt to reconnect to the master server when connection to it is lost. --- include/advertiser.h | 1 + src/advertiser.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/advertiser.h b/include/advertiser.h index 62ab1f6..99d6185 100644 --- a/include/advertiser.h +++ b/include/advertiser.h @@ -24,6 +24,7 @@ #include #include #include +#include /** * @brief A communicator class to update the master server on the server's status. diff --git a/src/advertiser.cpp b/src/advertiser.cpp index 5bc8aec..0f02622 100644 --- a/src/advertiser.cpp +++ b/src/advertiser.cpp @@ -62,6 +62,15 @@ void Advertiser::socketConnected() void Advertiser::socketDisconnected() { qDebug("Connection to master server lost"); + QTimer timer; + while (socket->state() == QAbstractSocket::UnconnectedState) { + timer.start(60000); + QEventLoop timer_loop; + connect(&timer, SIGNAL(timeout()), &timer_loop, SLOT(quit())); + timer_loop.exec(); + socket->connectToHost(ip, port); + socket->waitForConnected(); + } } void Advertiser::reloadRequested(QString p_name, QString p_desc)