refactor(liveupdates): use WebSocketPool over websocketpp (#6308)
Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
WebSocketPool::WebSocketPool() = default;
|
||||
WebSocketPool::WebSocketPool(QString shortName)
|
||||
: shortName(std::move(shortName)) {};
|
||||
|
||||
WebSocketPool::~WebSocketPool()
|
||||
{
|
||||
if (this->impl)
|
||||
@@ -34,7 +36,8 @@ WebSocketHandle WebSocketPool::createSocket(
|
||||
{
|
||||
try
|
||||
{
|
||||
this->impl = std::make_unique<ws::detail::WebSocketPoolImpl>();
|
||||
this->impl = std::make_unique<ws::detail::WebSocketPoolImpl>(
|
||||
this->shortName);
|
||||
}
|
||||
catch (const boost::system::system_error &err)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include <memory>
|
||||
@@ -74,7 +75,7 @@ struct WebSocketOptions {
|
||||
class WebSocketPool
|
||||
{
|
||||
public:
|
||||
WebSocketPool();
|
||||
WebSocketPool(QString shortName = {});
|
||||
~WebSocketPool();
|
||||
|
||||
[[nodiscard]] WebSocketHandle createSocket(
|
||||
@@ -82,6 +83,7 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<ws::detail::WebSocketPoolImpl> impl;
|
||||
QString shortName;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
#include "util/RenameThread.hpp"
|
||||
|
||||
#include <boost/certify/https_verification.hpp>
|
||||
#include <QStringBuilder>
|
||||
|
||||
namespace chatterino::ws::detail {
|
||||
|
||||
WebSocketPoolImpl::WebSocketPoolImpl()
|
||||
WebSocketPoolImpl::WebSocketPoolImpl(const QString &shortName)
|
||||
: ioc(1)
|
||||
, ssl(boost::asio::ssl::context::tls_client)
|
||||
, work(this->ioc.get_executor())
|
||||
@@ -43,7 +44,15 @@ WebSocketPoolImpl::WebSocketPoolImpl()
|
||||
this->ioc.run();
|
||||
this->shutdownFlag.set();
|
||||
});
|
||||
renameThread(*this->ioThread, "WebSocketPool");
|
||||
|
||||
auto threadName = [&]() -> QString {
|
||||
if (shortName.isEmpty())
|
||||
{
|
||||
return "WebSocketPool";
|
||||
}
|
||||
return "WS-" % shortName;
|
||||
}();
|
||||
renameThread(*this->ioThread, threadName);
|
||||
}
|
||||
|
||||
WebSocketPoolImpl::~WebSocketPoolImpl()
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/ssl/context.hpp>
|
||||
#include <QString>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
@@ -17,7 +18,7 @@ class WebSocketConnection;
|
||||
class WebSocketPoolImpl
|
||||
{
|
||||
public:
|
||||
WebSocketPoolImpl();
|
||||
WebSocketPoolImpl(const QString &shortName);
|
||||
~WebSocketPoolImpl();
|
||||
|
||||
WebSocketPoolImpl(const WebSocketPoolImpl &) = delete;
|
||||
|
||||
Reference in New Issue
Block a user