(socket server) wait for all connections threads to be terminated before exiting stop method

This commit is contained in:
Benjamin Sergeant 2019-04-19 16:31:33 -07:00
parent 9131cb4790
commit 662f66e501

View File

@ -137,8 +137,16 @@ namespace ix
void SocketServer::stop() void SocketServer::stop()
{ {
closeTerminatedThreads(); while (true)
assert(_connectionsThreads.empty()); {
closeTerminatedThreads();
if (_connectionsThreads.empty()) break;
// wait 10ms and try again later.
// we could have a timeout, but if we exit of here
// we leaked threads, it is quite bad.
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
if (!_thread.joinable()) return; // nothing to do if (!_thread.joinable()) return; // nothing to do