From 1778874ea8f99d48ad04f01b7f7623bf3eb46210 Mon Sep 17 00:00:00 2001 From: Dimon4eg Date: Fri, 10 May 2019 20:32:17 +0300 Subject: [PATCH] fix crash on close --- ixwebsocket/IXWebSocket.cpp | 16 ++++++---------- ixwebsocket/IXWebSocket.h | 2 -- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/ixwebsocket/IXWebSocket.cpp b/ixwebsocket/IXWebSocket.cpp index e87c403f..becc7b9d 100644 --- a/ixwebsocket/IXWebSocket.cpp +++ b/ixwebsocket/IXWebSocket.cpp @@ -144,18 +144,16 @@ namespace ix // This value needs to be forced when shutting down, it is restored later _automaticReconnection = false; + // sync close close(); - if (!_thread.joinable()) + if (_thread.joinable()) { - _automaticReconnection = automaticReconnection; - return; + _stop = true; + _thread.join(); + _stop = false; } - _stop = true; - _thread.join(); - _stop = false; - _automaticReconnection = automaticReconnection; } @@ -289,10 +287,8 @@ namespace ix { setThreadName(getUrl()); - while (true) + while (getReadyState() != WebSocket_ReadyState_Closed) { - if (_stop && !isClosing()) return; - // 1. Make sure we are always connected reconnectPerpetuallyIfDisconnected(); diff --git a/ixwebsocket/IXWebSocket.h b/ixwebsocket/IXWebSocket.h index 07c00a4a..5c6bc041 100644 --- a/ixwebsocket/IXWebSocket.h +++ b/ixwebsocket/IXWebSocket.h @@ -91,7 +91,6 @@ namespace ix void setUrl(const std::string& url); void setPerMessageDeflateOptions(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions); - void setHandshakeTimeout(int handshakeTimeoutSecs); void setHeartBeatPeriod(int heartBeatPeriodSecs); void setPingInterval(int pingIntervalSecs); // alias of setHeartBeatPeriod void setPingTimeout(int pingTimeoutSecs); @@ -142,7 +141,6 @@ namespace ix static void invokeTrafficTrackerCallback(size_t size, bool incoming); // Server - void setSocketFileDescriptor(int fd); WebSocketInitResult connectToSocket(int fd, int timeoutSecs); WebSocketTransport _ws;