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;
// 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++));
@ -270,11 +271,15 @@ namespace ix
connectErr, WebSocketOpenInfo(),
WebSocketCloseInfo());
// Only sleep if we aren't in the middle of stopping
if (!_stop)
{
std::this_thread::sleep_for(duration);
}
}
}
}
}
void WebSocket::run()
{