mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-17 16:58:50 +00:00
WSConnection clean shutdown, fix hubTrigger ownership (it's deleted by the event loop)
This commit is contained in:
@ -10,8 +10,8 @@ class WSConnection {
|
||||
std::string url;
|
||||
|
||||
uWS::Hub hub;
|
||||
uWS::Group<uWS::CLIENT> *hubGroup;
|
||||
std::unique_ptr<uS::Async> hubTrigger;
|
||||
uWS::Group<uWS::CLIENT> *hubGroup = nullptr;
|
||||
uS::Async *hubTrigger = nullptr;
|
||||
|
||||
uWS::WebSocket<uWS::CLIENT> *currWs = nullptr;
|
||||
|
||||
@ -29,6 +29,18 @@ class WSConnection {
|
||||
uint64_t reconnectDelayMilliseconds = 5'000;
|
||||
std::string remoteAddr;
|
||||
|
||||
~WSConnection() {
|
||||
close();
|
||||
}
|
||||
|
||||
void close() {
|
||||
if (hubGroup) hubGroup->close();
|
||||
hubGroup = nullptr;
|
||||
|
||||
if (hubTrigger) hubTrigger->close();
|
||||
hubTrigger = nullptr;
|
||||
}
|
||||
|
||||
// Should only be called from the websocket thread (ie within an onConnect or onMessage callback)
|
||||
void send(std::string_view msg, uWS::OpCode op = uWS::OpCode::TEXT, size_t *compressedSize = nullptr) {
|
||||
if (currWs) {
|
||||
@ -120,7 +132,7 @@ class WSConnection {
|
||||
}
|
||||
};
|
||||
|
||||
hubTrigger = std::make_unique<uS::Async>(hub.getLoop());
|
||||
hubTrigger = new uS::Async(hub.getLoop());
|
||||
hubTrigger->setData(&asyncCb);
|
||||
|
||||
hubTrigger->start([](uS::Async *a){
|
||||
|
@ -149,7 +149,7 @@ struct MsgNegentropy : NonCopyable {
|
||||
|
||||
|
||||
struct RelayServer {
|
||||
std::unique_ptr<uS::Async> hubTrigger;
|
||||
uS::Async *hubTrigger = nullptr;
|
||||
|
||||
// Thread Pools
|
||||
|
||||
|
@ -39,7 +39,7 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
|
||||
};
|
||||
|
||||
uWS::Hub hub;
|
||||
uWS::Group<uWS::SERVER> *hubGroup;
|
||||
uWS::Group<uWS::SERVER> *hubGroup = nullptr;
|
||||
flat_hash_map<uint64_t, Connection*> connIdToConnection;
|
||||
uint64_t nextConnectionId = 1;
|
||||
bool gracefulShutdown = false;
|
||||
@ -219,7 +219,7 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
|
||||
}
|
||||
};
|
||||
|
||||
hubTrigger = std::make_unique<uS::Async>(hub.getLoop());
|
||||
hubTrigger = new uS::Async(hub.getLoop());
|
||||
hubTrigger->setData(&asyncCb);
|
||||
|
||||
hubTrigger->start([](uS::Async *a){
|
||||
|
Reference in New Issue
Block a user