(ixwebsocket) New option to set the min wait between reconnection attempts. Still default to 1ms. (setMinWaitBetweenReconnectionRetries).
This commit is contained in:
parent
def0243d6d
commit
d26664fccc
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
All changes to this project will be documented in this file.
|
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
|
## [11.1.2] - 2021-03-22
|
||||||
|
|
||||||
(ws) initialize maxWaitBetweenReconnectionRetries to a non zero value ; a zero value was causing spurious reconnections attempts
|
(ws) initialize maxWaitBetweenReconnectionRetries to a non zero value ; a zero value was causing spurious reconnections attempts
|
||||||
|
@ -256,11 +256,15 @@ Wait time(ms): 6400
|
|||||||
Wait time(ms): 10000
|
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
|
```cpp
|
||||||
webSocket.setMaxWaitBetweenReconnectionRetries(5 * 1000); // 5000ms = 5s
|
webSocket.setMaxWaitBetweenReconnectionRetries(5 * 1000); // 5000ms = 5s
|
||||||
uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries();
|
uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries();
|
||||||
|
|
||||||
|
webSocket.setMinWaitBetweenReconnectionRetries(1000); // 1000ms = 1s
|
||||||
|
uint32_t m = webSocket.getMinWaitBetweenReconnectionRetries();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Handshake timeout
|
## Handshake timeout
|
||||||
|
@ -22,12 +22,14 @@ namespace ix
|
|||||||
const int WebSocket::kDefaultPingIntervalSecs(-1);
|
const int WebSocket::kDefaultPingIntervalSecs(-1);
|
||||||
const bool WebSocket::kDefaultEnablePong(true);
|
const bool WebSocket::kDefaultEnablePong(true);
|
||||||
const uint32_t WebSocket::kDefaultMaxWaitBetweenReconnectionRetries(10 * 1000); // 10s
|
const uint32_t WebSocket::kDefaultMaxWaitBetweenReconnectionRetries(10 * 1000); // 10s
|
||||||
|
const uint32_t WebSocket::kDefaultMinWaitBetweenReconnectionRetries(1); // 1 ms
|
||||||
|
|
||||||
WebSocket::WebSocket()
|
WebSocket::WebSocket()
|
||||||
: _onMessageCallback(OnMessageCallback())
|
: _onMessageCallback(OnMessageCallback())
|
||||||
, _stop(false)
|
, _stop(false)
|
||||||
, _automaticReconnection(true)
|
, _automaticReconnection(true)
|
||||||
, _maxWaitBetweenReconnectionRetries(kDefaultMaxWaitBetweenReconnectionRetries)
|
, _maxWaitBetweenReconnectionRetries(kDefaultMaxWaitBetweenReconnectionRetries)
|
||||||
|
, _minWaitBetweenReconnectionRetries(kDefaultMinWaitBetweenReconnectionRetries)
|
||||||
, _handshakeTimeoutSecs(kDefaultHandShakeTimeoutSecs)
|
, _handshakeTimeoutSecs(kDefaultHandShakeTimeoutSecs)
|
||||||
, _enablePong(kDefaultEnablePong)
|
, _enablePong(kDefaultEnablePong)
|
||||||
, _pingIntervalSecs(kDefaultPingIntervalSecs)
|
, _pingIntervalSecs(kDefaultPingIntervalSecs)
|
||||||
@ -136,12 +138,24 @@ namespace ix
|
|||||||
_maxWaitBetweenReconnectionRetries = maxWaitBetweenReconnectionRetries;
|
_maxWaitBetweenReconnectionRetries = maxWaitBetweenReconnectionRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebSocket::setMinWaitBetweenReconnectionRetries(uint32_t minWaitBetweenReconnectionRetries)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_configMutex);
|
||||||
|
_minWaitBetweenReconnectionRetries = minWaitBetweenReconnectionRetries;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t WebSocket::getMaxWaitBetweenReconnectionRetries() const
|
uint32_t WebSocket::getMaxWaitBetweenReconnectionRetries() const
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_configMutex);
|
std::lock_guard<std::mutex> lock(_configMutex);
|
||||||
return _maxWaitBetweenReconnectionRetries;
|
return _maxWaitBetweenReconnectionRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t WebSocket::getMinWaitBetweenReconnectionRetries() const
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_configMutex);
|
||||||
|
return _minWaitBetweenReconnectionRetries;
|
||||||
|
}
|
||||||
|
|
||||||
void WebSocket::start()
|
void WebSocket::start()
|
||||||
{
|
{
|
||||||
if (_thread.joinable()) return; // we've already been started
|
if (_thread.joinable()) return; // we've already been started
|
||||||
@ -311,8 +325,10 @@ namespace ix
|
|||||||
|
|
||||||
if (_automaticReconnection)
|
if (_automaticReconnection)
|
||||||
{
|
{
|
||||||
duration = millis(calculateRetryWaitMilliseconds(
|
duration =
|
||||||
retries++, _maxWaitBetweenReconnectionRetries));
|
millis(calculateRetryWaitMilliseconds(retries++,
|
||||||
|
_maxWaitBetweenReconnectionRetries,
|
||||||
|
_minWaitBetweenReconnectionRetries));
|
||||||
|
|
||||||
connectErr.wait_time = duration.count();
|
connectErr.wait_time = duration.count();
|
||||||
connectErr.retries = retries;
|
connectErr.retries = retries;
|
||||||
|
@ -101,6 +101,7 @@ namespace ix
|
|||||||
void disableAutomaticReconnection();
|
void disableAutomaticReconnection();
|
||||||
bool isAutomaticReconnectionEnabled() const;
|
bool isAutomaticReconnectionEnabled() const;
|
||||||
void setMaxWaitBetweenReconnectionRetries(uint32_t maxWaitBetweenReconnectionRetries);
|
void setMaxWaitBetweenReconnectionRetries(uint32_t maxWaitBetweenReconnectionRetries);
|
||||||
|
void setMinWaitBetweenReconnectionRetries(uint32_t minWaitBetweenReconnectionRetries);
|
||||||
uint32_t getMaxWaitBetweenReconnectionRetries() const;
|
uint32_t getMaxWaitBetweenReconnectionRetries() const;
|
||||||
const std::vector<std::string>& getSubProtocols();
|
const std::vector<std::string>& getSubProtocols();
|
||||||
|
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "11.1.2"
|
#define IX_WEBSOCKET_VERSION "11.1.3"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user