This commit is contained in:
Benjamin Sergeant 2019-04-29 16:15:26 -07:00
parent 225aade89d
commit bbf34aef29

View File

@ -230,11 +230,11 @@ namespace ix
millis duration; millis duration;
// Try to connect only once when we don't have automaticReconnection setup // Try to connect only once when we don't have automaticReconnection setup
if (!isConnected() && !_automaticReconnection && !_stop) if (!isConnected() && !isClosing() && !_stop && !_automaticReconnection)
{ {
status = connect(_handshakeTimeoutSecs); status = connect(_handshakeTimeoutSecs);
if (!status.success && !_stop) if (!status.success)
{ {
duration = millis(calculateRetryWaitMilliseconds(retries++)); duration = millis(calculateRetryWaitMilliseconds(retries++));
@ -249,6 +249,7 @@ namespace ix
} }
else else
{ {
// Otherwise try to reconnect perpertually
while (true) while (true)
{ {
if (isConnected() || isClosing() || _stop || !_automaticReconnection) if (isConnected() || isClosing() || _stop || !_automaticReconnection)
@ -258,7 +259,7 @@ namespace ix
status = connect(_handshakeTimeoutSecs); status = connect(_handshakeTimeoutSecs);
if (!status.success && !_stop) if (!status.success)
{ {
duration = millis(calculateRetryWaitMilliseconds(retries++)); duration = millis(calculateRetryWaitMilliseconds(retries++));
@ -270,7 +271,11 @@ namespace ix
connectErr, WebSocketOpenInfo(), connectErr, WebSocketOpenInfo(),
WebSocketCloseInfo()); 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);
}
} }
} }
} }