fix: cleanly exit on shutdown (#5537)

Co-authored-by: Mm2PL <mm2pl+gh@kotmisia.pl>
Co-authored-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
pajlada
2024-08-10 14:24:25 +02:00
committed by GitHub
parent daff83dde8
commit 74d65a345d
23 changed files with 134 additions and 65 deletions
@@ -150,6 +150,15 @@ protected:
return this->started_.load(std::memory_order_acquire);
}
/**
* @brief Will be called when the clients has been requested to stop
*
* Derived classes can override this to implement their own shutdown behaviour
*/
virtual void stopImpl()
{
}
liveupdates::WebsocketClient &websocketClient_;
private:
@@ -164,6 +173,8 @@ private:
{
assert(this->isStarted());
this->started_.store(false, std::memory_order_release);
this->stopImpl();
}
liveupdates::WebsocketHandle handle_;
@@ -8,10 +8,12 @@
#include "providers/twitch/PubSubHelpers.hpp"
#include "util/DebugCount.hpp"
#include "util/ExponentialBackoff.hpp"
#include "util/RenameThread.hpp"
#include <pajlada/signals/signal.hpp>
#include <QJsonObject>
#include <QString>
#include <QStringBuilder>
#include <websocketpp/client.hpp>
#include <algorithm>
@@ -59,8 +61,9 @@ template <typename Subscription>
class BasicPubSubManager
{
public:
BasicPubSubManager(QString host)
BasicPubSubManager(QString host, QString shortName)
: host_(std::move(host))
, shortName_(std::move(shortName))
{
this->websocketClient_.set_access_channels(
websocketpp::log::alevel::all);
@@ -94,7 +97,10 @@ public:
.toStdString());
}
virtual ~BasicPubSubManager() = default;
virtual ~BasicPubSubManager()
{
this->stop();
}
BasicPubSubManager(const BasicPubSubManager &) = delete;
BasicPubSubManager(const BasicPubSubManager &&) = delete;
@@ -115,6 +121,8 @@ public:
this->mainThread_.reset(new std::thread([this] {
runThread();
}));
renameThread(*this->mainThread_.get(), "BPSM-" % this->shortName_);
}
void stop()
@@ -373,6 +381,9 @@ private:
const QString host_;
/// Short name of the service (e.g. "7TV" or "BTTV")
const QString shortName_;
bool stopping_{false};
};