rename some variables, minor cleanup

This commit is contained in:
Benjamin Sergeant 2019-05-11 10:24:28 -07:00
parent 5eb23c9764
commit 2dc1547bbd
2 changed files with 15 additions and 16 deletions

View File

@ -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)
{ {
@ -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)

View File

@ -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);