rename some variables, minor cleanup
This commit is contained in:
parent
5eb23c9764
commit
2dc1547bbd
@ -222,15 +222,14 @@ namespace ix
|
|||||||
_ws.close();
|
_ws.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocket::checkConnection(bool initial)
|
void WebSocket::checkConnection(bool firstConnectionAttempt)
|
||||||
{
|
{
|
||||||
using millis = std::chrono::duration<double, std::milli>;
|
using millis = std::chrono::duration<double, std::milli>;
|
||||||
|
|
||||||
uint32_t retries = 0;
|
uint32_t retries = 0;
|
||||||
millis duration;
|
millis duration;
|
||||||
ix::WebSocketInitResult status;
|
|
||||||
|
|
||||||
// we will try to connect perpertually
|
// Try to connect perpertually
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (isConnected() || isClosing() || _stop)
|
if (isConnected() || isClosing() || _stop)
|
||||||
@ -238,23 +237,23 @@ namespace ix
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!initial && !_automaticReconnection)
|
if (!firstConnectionAttempt && !_automaticReconnection)
|
||||||
{
|
{
|
||||||
// don't attempt to reconnect
|
// Do not attempt to reconnect
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
initial = false;
|
firstConnectionAttempt = false;
|
||||||
|
|
||||||
// Only sleep if we are retrying
|
// Only sleep if we are retrying
|
||||||
if (duration.count() > 0)
|
if (retries != 0)
|
||||||
{
|
{
|
||||||
// to do: make conditional sleeping
|
// to do: make sleeping conditional
|
||||||
std::this_thread::sleep_for(duration);
|
std::this_thread::sleep_for(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to connect (sync connect)
|
// Try to connect synchronously
|
||||||
status = connect(_handshakeTimeoutSecs);
|
ix::WebSocketInitResult status = connect(_handshakeTimeoutSecs);
|
||||||
|
|
||||||
if (!status.success)
|
if (!status.success)
|
||||||
{
|
{
|
||||||
@ -272,8 +271,8 @@ namespace ix
|
|||||||
connectErr.http_status = status.http_status;
|
connectErr.http_status = status.http_status;
|
||||||
|
|
||||||
_onMessageCallback(WebSocket_MessageType_Error, "", 0,
|
_onMessageCallback(WebSocket_MessageType_Error, "", 0,
|
||||||
connectErr, WebSocketOpenInfo(),
|
connectErr, WebSocketOpenInfo(),
|
||||||
WebSocketCloseInfo());
|
WebSocketCloseInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,14 +281,14 @@ namespace ix
|
|||||||
{
|
{
|
||||||
setThreadName(getUrl());
|
setThreadName(getUrl());
|
||||||
|
|
||||||
bool initial = true;
|
bool firstConnectionAttempt = true;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// 1. Make sure we are always connected
|
// 1. Make sure we are always connected
|
||||||
checkConnection(initial);
|
checkConnection(firstConnectionAttempt);
|
||||||
|
|
||||||
initial = false;
|
firstConnectionAttempt = false;
|
||||||
|
|
||||||
// if here we are closed then checkConnection was not able to connect
|
// if here we are closed then checkConnection was not able to connect
|
||||||
if (getReadyState() == WebSocket_ReadyState_Closed)
|
if (getReadyState() == WebSocket_ReadyState_Closed)
|
||||||
|
@ -136,7 +136,7 @@ namespace ix
|
|||||||
|
|
||||||
bool isConnected() const;
|
bool isConnected() const;
|
||||||
bool isClosing() const;
|
bool isClosing() const;
|
||||||
void checkConnection(bool initial);
|
void checkConnection(bool firstConnectionAttempt);
|
||||||
std::string readyStateToString(ReadyState readyState);
|
std::string readyStateToString(ReadyState readyState);
|
||||||
static void invokeTrafficTrackerCallback(size_t size, bool incoming);
|
static void invokeTrafficTrackerCallback(size_t size, bool incoming);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user