fix ping, fix send frame close (#49)

* fix ping, fix send frame close

* fixes for data race on _closeCode etc. and fix test

* fixing one TC

* fix waiting forever if no time to change of readyState, and poll never end

* add 1005 code if no status code received

* fixes for 1005 code

* fix test issue

* fix macOS issue

* revert to master tests and renaming
This commit is contained in:
Kumamon38
2019-05-09 18:21:05 +02:00
committed by Benjamin Sergeant
parent 28c3f2ea26
commit cb1d1bfd85
9 changed files with 433 additions and 162 deletions

View File

@ -215,6 +215,11 @@ namespace ix
return getReadyState() == WebSocket_ReadyState_Closing;
}
bool WebSocket::isConnectedOrClosing() const
{
return isConnected() || isClosing();
}
void WebSocket::close()
{
_ws.close();
@ -229,7 +234,7 @@ namespace ix
millis duration;
// Try to connect only once when we don't have automaticReconnection setup
if (!isConnected() && !isClosing() && !_stop && !_automaticReconnection)
if (!isConnectedOrClosing() && !_stop && !_automaticReconnection)
{
status = connect(_handshakeTimeoutSecs);
@ -251,7 +256,7 @@ namespace ix
// Otherwise try to reconnect perpertually
while (true)
{
if (isConnected() || isClosing() || _stop || !_automaticReconnection)
if (isConnectedOrClosing() || _stop || !_automaticReconnection)
{
break;
}
@ -286,20 +291,17 @@ namespace ix
while (true)
{
if (_stop) return;
if (_stop && !isClosing()) return;
// 1. Make sure we are always connected
reconnectPerpetuallyIfDisconnected();
if (_stop) return;
// 2. Poll to see if there's any new data available
_ws.poll();
if (_stop) return;
WebSocketTransport::PollPostTreatment pollPostTreatment = _ws.poll();
// 3. Dispatch the incoming messages
_ws.dispatch(
pollPostTreatment,
[this](const std::string& msg,
size_t wireSize,
bool decompressionError,
@ -340,7 +342,7 @@ namespace ix
});
// If we aren't trying to reconnect automatically, exit if we aren't connected
if (!isConnected() && !_automaticReconnection) return;
if (!isConnectedOrClosing() && !_automaticReconnection) return;
}
}