save timepoints after connect and not in contructor, adjusted tests (#72)

* save timepoints after connect and not in contructor, adjusted tests

* move call into setReadyState

* more time to detect client close in test
This commit is contained in:
Kumamon38
2019-05-13 18:08:46 +02:00
committed by Benjamin Sergeant
parent 22a806ca6f
commit 4b96632a69
4 changed files with 30 additions and 12 deletions

View File

@ -134,11 +134,6 @@ namespace ix
{
_pingIntervalOrTimeoutGCDSecs = pingIntervalSecs;
}
if (_pingIntervalOrTimeoutGCDSecs > 0)
{
_nextGCDTimePoint = std::chrono::steady_clock::now() + std::chrono::seconds(_pingIntervalOrTimeoutGCDSecs);
}
}
// Client
@ -225,6 +220,10 @@ namespace ix
_closeWireSize = 0;
_closeRemote = false;
}
else if (readyState == ReadyState::OPEN)
{
initTimePointsAndGCDAfterConnect();
}
_readyState = readyState;
}
@ -234,6 +233,23 @@ namespace ix
_onCloseCallback = onCloseCallback;
}
void WebSocketTransport::initTimePointsAndGCDAfterConnect()
{
{
std::lock_guard<std::mutex> lock(_lastSendPingTimePointMutex);
_lastSendPingTimePoint = std::chrono::steady_clock::now();
}
{
std::lock_guard<std::mutex> lock(_lastReceivePongTimePointMutex);
_lastReceivePongTimePoint = std::chrono::steady_clock::now();
}
if (_pingIntervalOrTimeoutGCDSecs > 0)
{
_nextGCDTimePoint = std::chrono::steady_clock::now() + std::chrono::seconds(_pingIntervalOrTimeoutGCDSecs);
}
}
// Only consider send PING time points for that computation.
bool WebSocketTransport::pingIntervalExceeded()
{

View File

@ -220,6 +220,8 @@ namespace ix
// after calling close(), if no CLOSE frame answer is received back from the remote, we should close the connexion
bool closingDelayExceeded();
void initTimePointsAndGCDAfterConnect();
void sendCloseFrame(uint16_t code, const std::string& reason);
void closeSocketAndSwitchToClosedState(uint16_t code,