From f563d141345bb9c725a354ca2dc1fc3a241d2510 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Wed, 24 Apr 2019 09:45:53 -0700 Subject: [PATCH] better server termination / another try at preventing thread join failures --- ixwebsocket/IXSocketServer.cpp | 7 +++++++ ixwebsocket/IXSocketServer.h | 2 ++ ixwebsocket/IXWebSocketServer.cpp | 2 ++ 3 files changed, 11 insertions(+) diff --git a/ixwebsocket/IXSocketServer.cpp b/ixwebsocket/IXSocketServer.cpp index eb8d8ed6..40abbbba 100644 --- a/ixwebsocket/IXSocketServer.cpp +++ b/ixwebsocket/IXSocketServer.cpp @@ -135,6 +135,11 @@ namespace ix _conditionVariable.wait(lock); } + void SocketServer::stopAcceptingConnections() + { + _stop = true; + } + void SocketServer::stop() { while (true) @@ -270,6 +275,8 @@ namespace ix connectionState = _connectionStateFactory(); } + if (_stop) return; + // Launch the handleConnection work asynchronously in its own thread. _connectionsThreads.push_back(std::make_pair( connectionState, diff --git a/ixwebsocket/IXSocketServer.h b/ixwebsocket/IXSocketServer.h index 66a5f350..79d2c153 100644 --- a/ixwebsocket/IXSocketServer.h +++ b/ixwebsocket/IXSocketServer.h @@ -57,6 +57,8 @@ namespace ix void logError(const std::string& str); void logInfo(const std::string& str); + void stopAcceptingConnections(); + private: // Member variables int _port; diff --git a/ixwebsocket/IXWebSocketServer.cpp b/ixwebsocket/IXWebSocketServer.cpp index 7582c9ba..dc895b96 100644 --- a/ixwebsocket/IXWebSocketServer.cpp +++ b/ixwebsocket/IXWebSocketServer.cpp @@ -37,6 +37,8 @@ namespace ix void WebSocketServer::stop() { + stopAcceptingConnections(); + auto clients = getClients(); for (auto client : clients) {