diff --git a/ixwebsocket/IXExponentialBackoff.cpp b/ixwebsocket/IXExponentialBackoff.cpp index 007d22cf..1bb57ee5 100644 --- a/ixwebsocket/IXExponentialBackoff.cpp +++ b/ixwebsocket/IXExponentialBackoff.cpp @@ -10,16 +10,22 @@ namespace ix { - uint32_t calculateRetryWaitMilliseconds(uint32_t retry_count, - uint32_t maxWaitBetweenReconnectionRetries) + uint32_t calculateRetryWaitMilliseconds(uint32_t retryCount, + uint32_t maxWaitBetweenReconnectionRetries, + uint32_t minWaitBetweenReconnectionRetries) { - uint32_t wait_time = (retry_count < 26) ? (std::pow(2, retry_count) * 100) : 0; + uint32_t waitTime = (retryCount < 26) ? (std::pow(2, retryCount) * 100) : 0; - if (wait_time > maxWaitBetweenReconnectionRetries || wait_time == 0) + if (waitTime < minWaitBetweenReconnectionRetries) { - wait_time = maxWaitBetweenReconnectionRetries; + waitTime = minWaitBetweenReconnectionRetries; } - return wait_time; + if (waitTime > maxWaitBetweenReconnectionRetries || waitTime == 0) + { + waitTime = maxWaitBetweenReconnectionRetries; + } + + return waitTime; } } // namespace ix diff --git a/ixwebsocket/IXExponentialBackoff.h b/ixwebsocket/IXExponentialBackoff.h index 100f6a60..79e19e9f 100644 --- a/ixwebsocket/IXExponentialBackoff.h +++ b/ixwebsocket/IXExponentialBackoff.h @@ -10,6 +10,7 @@ namespace ix { - uint32_t calculateRetryWaitMilliseconds(uint32_t retry_count, - uint32_t maxWaitBetweenReconnectionRetries); + uint32_t calculateRetryWaitMilliseconds(uint32_t retryCount, + uint32_t maxWaitBetweenReconnectionRetries, + uint32_t minWaitBetweenReconnectionRetries); } // namespace ix diff --git a/ixwebsocket/IXWebSocket.h b/ixwebsocket/IXWebSocket.h index 10c2283c..3d5c8c52 100644 --- a/ixwebsocket/IXWebSocket.h +++ b/ixwebsocket/IXWebSocket.h @@ -103,6 +103,7 @@ namespace ix void setMaxWaitBetweenReconnectionRetries(uint32_t maxWaitBetweenReconnectionRetries); void setMinWaitBetweenReconnectionRetries(uint32_t minWaitBetweenReconnectionRetries); uint32_t getMaxWaitBetweenReconnectionRetries() const; + uint32_t getMinWaitBetweenReconnectionRetries() const; const std::vector& getSubProtocols(); private: @@ -141,7 +142,9 @@ namespace ix // Automatic reconnection std::atomic _automaticReconnection; static const uint32_t kDefaultMaxWaitBetweenReconnectionRetries; + static const uint32_t kDefaultMinWaitBetweenReconnectionRetries; uint32_t _maxWaitBetweenReconnectionRetries; + uint32_t _minWaitBetweenReconnectionRetries; // Make the sleeping in the automatic reconnection cancellable std::mutex _sleepMutex;