mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-18 09:17:12 +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;
|
std::string url;
|
||||||
|
|
||||||
uWS::Hub hub;
|
uWS::Hub hub;
|
||||||
uWS::Group<uWS::CLIENT> *hubGroup;
|
uWS::Group<uWS::CLIENT> *hubGroup = nullptr;
|
||||||
std::unique_ptr<uS::Async> hubTrigger;
|
uS::Async *hubTrigger = nullptr;
|
||||||
|
|
||||||
uWS::WebSocket<uWS::CLIENT> *currWs = nullptr;
|
uWS::WebSocket<uWS::CLIENT> *currWs = nullptr;
|
||||||
|
|
||||||
@ -29,6 +29,18 @@ class WSConnection {
|
|||||||
uint64_t reconnectDelayMilliseconds = 5'000;
|
uint64_t reconnectDelayMilliseconds = 5'000;
|
||||||
std::string remoteAddr;
|
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)
|
// 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) {
|
void send(std::string_view msg, uWS::OpCode op = uWS::OpCode::TEXT, size_t *compressedSize = nullptr) {
|
||||||
if (currWs) {
|
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->setData(&asyncCb);
|
||||||
|
|
||||||
hubTrigger->start([](uS::Async *a){
|
hubTrigger->start([](uS::Async *a){
|
||||||
|
@ -149,7 +149,7 @@ struct MsgNegentropy : NonCopyable {
|
|||||||
|
|
||||||
|
|
||||||
struct RelayServer {
|
struct RelayServer {
|
||||||
std::unique_ptr<uS::Async> hubTrigger;
|
uS::Async *hubTrigger = nullptr;
|
||||||
|
|
||||||
// Thread Pools
|
// Thread Pools
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
uWS::Hub hub;
|
uWS::Hub hub;
|
||||||
uWS::Group<uWS::SERVER> *hubGroup;
|
uWS::Group<uWS::SERVER> *hubGroup = nullptr;
|
||||||
flat_hash_map<uint64_t, Connection*> connIdToConnection;
|
flat_hash_map<uint64_t, Connection*> connIdToConnection;
|
||||||
uint64_t nextConnectionId = 1;
|
uint64_t nextConnectionId = 1;
|
||||||
bool gracefulShutdown = false;
|
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->setData(&asyncCb);
|
||||||
|
|
||||||
hubTrigger->start([](uS::Async *a){
|
hubTrigger->start([](uS::Async *a){
|
||||||
|
Reference in New Issue
Block a user