diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8c874ce6..afeffb9e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ All changes to this project will be documented in this file. +## [11.1.3] - 2021-03-23 + +(ixwebsocket) New option to set the min wait between reconnection attempts. Still default to 1ms. (setMinWaitBetweenReconnectionRetries). + ## [11.1.2] - 2021-03-22 (ws) initialize maxWaitBetweenReconnectionRetries to a non zero value ; a zero value was causing spurious reconnections attempts diff --git a/docs/usage.md b/docs/usage.md index 655cba07..c5408f84 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -256,11 +256,15 @@ Wait time(ms): 6400 Wait time(ms): 10000 ``` -The waiting time is capped by default at 10s between 2 attempts, but that value can be changed and queried. +The waiting time is capped by default at 10s between 2 attempts, but that value +can be changed and queried. The minimum waiting time can also be set. ```cpp webSocket.setMaxWaitBetweenReconnectionRetries(5 * 1000); // 5000ms = 5s uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries(); + +webSocket.setMinWaitBetweenReconnectionRetries(1000); // 1000ms = 1s +uint32_t m = webSocket.getMinWaitBetweenReconnectionRetries(); ``` ## Handshake timeout diff --git a/ixwebsocket/IXWebSocket.cpp b/ixwebsocket/IXWebSocket.cpp index 490169dc..e0815ad3 100644 --- a/ixwebsocket/IXWebSocket.cpp +++ b/ixwebsocket/IXWebSocket.cpp @@ -22,12 +22,14 @@ namespace ix const int WebSocket::kDefaultPingIntervalSecs(-1); const bool WebSocket::kDefaultEnablePong(true); const uint32_t WebSocket::kDefaultMaxWaitBetweenReconnectionRetries(10 * 1000); // 10s + const uint32_t WebSocket::kDefaultMinWaitBetweenReconnectionRetries(1); // 1 ms WebSocket::WebSocket() : _onMessageCallback(OnMessageCallback()) , _stop(false) , _automaticReconnection(true) , _maxWaitBetweenReconnectionRetries(kDefaultMaxWaitBetweenReconnectionRetries) + , _minWaitBetweenReconnectionRetries(kDefaultMinWaitBetweenReconnectionRetries) , _handshakeTimeoutSecs(kDefaultHandShakeTimeoutSecs) , _enablePong(kDefaultEnablePong) , _pingIntervalSecs(kDefaultPingIntervalSecs) @@ -136,12 +138,24 @@ namespace ix _maxWaitBetweenReconnectionRetries = maxWaitBetweenReconnectionRetries; } + void WebSocket::setMinWaitBetweenReconnectionRetries(uint32_t minWaitBetweenReconnectionRetries) + { + std::lock_guard lock(_configMutex); + _minWaitBetweenReconnectionRetries = minWaitBetweenReconnectionRetries; + } + uint32_t WebSocket::getMaxWaitBetweenReconnectionRetries() const { std::lock_guard lock(_configMutex); return _maxWaitBetweenReconnectionRetries; } + uint32_t WebSocket::getMinWaitBetweenReconnectionRetries() const + { + std::lock_guard lock(_configMutex); + return _minWaitBetweenReconnectionRetries; + } + void WebSocket::start() { if (_thread.joinable()) return; // we've already been started @@ -311,8 +325,10 @@ namespace ix if (_automaticReconnection) { - duration = millis(calculateRetryWaitMilliseconds( - retries++, _maxWaitBetweenReconnectionRetries)); + duration = + millis(calculateRetryWaitMilliseconds(retries++, + _maxWaitBetweenReconnectionRetries, + _minWaitBetweenReconnectionRetries)); connectErr.wait_time = duration.count(); connectErr.retries = retries; diff --git a/ixwebsocket/IXWebSocket.h b/ixwebsocket/IXWebSocket.h index 2fec734e..10c2283c 100644 --- a/ixwebsocket/IXWebSocket.h +++ b/ixwebsocket/IXWebSocket.h @@ -101,6 +101,7 @@ namespace ix void disableAutomaticReconnection(); bool isAutomaticReconnectionEnabled() const; void setMaxWaitBetweenReconnectionRetries(uint32_t maxWaitBetweenReconnectionRetries); + void setMinWaitBetweenReconnectionRetries(uint32_t minWaitBetweenReconnectionRetries); uint32_t getMaxWaitBetweenReconnectionRetries() const; const std::vector& getSubProtocols(); diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 0c4d1797..7af8c3ce 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "11.1.2" +#define IX_WEBSOCKET_VERSION "11.1.3"