From bbf34aef29e6445afdfadf96bd934a28211bb239 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Mon, 29 Apr 2019 16:15:26 -0700 Subject: [PATCH] cleanup --- ixwebsocket/IXWebSocket.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ixwebsocket/IXWebSocket.cpp b/ixwebsocket/IXWebSocket.cpp index fc4f88b4..c326982d 100644 --- a/ixwebsocket/IXWebSocket.cpp +++ b/ixwebsocket/IXWebSocket.cpp @@ -230,11 +230,11 @@ namespace ix millis duration; // Try to connect only once when we don't have automaticReconnection setup - if (!isConnected() && !_automaticReconnection && !_stop) + if (!isConnected() && !isClosing() && !_stop && !_automaticReconnection) { status = connect(_handshakeTimeoutSecs); - if (!status.success && !_stop) + if (!status.success) { duration = millis(calculateRetryWaitMilliseconds(retries++)); @@ -249,6 +249,7 @@ namespace ix } else { + // Otherwise try to reconnect perpertually while (true) { if (isConnected() || isClosing() || _stop || !_automaticReconnection) @@ -258,7 +259,7 @@ namespace ix status = connect(_handshakeTimeoutSecs); - if (!status.success && !_stop) + if (!status.success) { duration = millis(calculateRetryWaitMilliseconds(retries++)); @@ -269,8 +270,12 @@ namespace ix _onMessageCallback(WebSocket_MessageType_Error, "", 0, connectErr, WebSocketOpenInfo(), WebSocketCloseInfo()); - - std::this_thread::sleep_for(duration); + + // Only sleep if we aren't in the middle of stopping + if (!_stop) + { + std::this_thread::sleep_for(duration); + } } } }