Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions ixwebsocket/IXWebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,23 @@ namespace ix

void WebSocket::stop(uint16_t code, const std::string& reason)
{
const bool isJoinable = _thread.joinable();

if(isJoinable)
{
// we need to set _stop before close()
// otherwise automatic reconnection might restart the connection before _stop has a chance to get set
// this can happen during high CPU load => _thread.join() below blocks indefinitely
_stop = true;
_sleepCondition.notify_one();
}

close(code, reason);

if (_thread.joinable())
if (isJoinable)
{
// wait until working thread will exit
// it will exit after close operation is finished
_stop = true;
_sleepCondition.notify_one();
_thread.join();
_stop = false;
}
Expand Down
Loading