unittest pass + commands behave as expected

This commit is contained in:
Benjamin Sergeant 2019-04-29 15:27:04 -07:00
parent 705e0823cb
commit 225aade89d
2 changed files with 30 additions and 8 deletions

View File

@ -229,13 +229,9 @@ namespace ix
using millis = std::chrono::duration<double, std::milli>;
millis duration;
while (true)
// Try to connect only once when we don't have automaticReconnection setup
if (!isConnected() && !_automaticReconnection && !_stop)
{
if (isConnected() || isClosing() || _stop || !_automaticReconnection)
{
break;
}
status = connect(_handshakeTimeoutSecs);
if (!status.success && !_stop)
@ -249,8 +245,33 @@ namespace ix
_onMessageCallback(WebSocket_MessageType_Error, "", 0,
connectErr, WebSocketOpenInfo(),
WebSocketCloseInfo());
}
}
else
{
while (true)
{
if (isConnected() || isClosing() || _stop || !_automaticReconnection)
{
break;
}
std::this_thread::sleep_for(duration);
status = connect(_handshakeTimeoutSecs);
if (!status.success && !_stop)
{
duration = millis(calculateRetryWaitMilliseconds(retries++));
connectErr.retries = retries;
connectErr.wait_time = duration.count();
connectErr.reason = status.errorStr;
connectErr.http_status = status.http_status;
_onMessageCallback(WebSocket_MessageType_Error, "", 0,
connectErr, WebSocketOpenInfo(),
WebSocketCloseInfo());
std::this_thread::sleep_for(duration);
}
}
}
}
@ -317,7 +338,7 @@ namespace ix
// 4. In blocking mode, getting out of this function is triggered by
// an explicit disconnection from the callback, or by the remote end
// closing the connection, ie isConnected() == false.
if (!_thread.joinable() && !isConnected() && !_automaticReconnection) return;
if (!isConnected() && !_automaticReconnection) return;
}
}

View File

@ -39,6 +39,7 @@ namespace ix
std::cout << "Disabling automatic reconnection with "
"_webSocket.disableAutomaticReconnection()"
" not supported yet" << std::endl;
_webSocket.disableAutomaticReconnection();
}
}