indentation / comestic changes
This commit is contained in:
parent
0dfc66f1c7
commit
d48bf9249b
@ -100,7 +100,8 @@ namespace ix
|
|||||||
|
|
||||||
void WebSocketTransport::configure(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions,
|
void WebSocketTransport::configure(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions,
|
||||||
bool enablePong,
|
bool enablePong,
|
||||||
int pingIntervalSecs, int pingTimeoutSecs)
|
int pingIntervalSecs,
|
||||||
|
int pingTimeoutSecs)
|
||||||
{
|
{
|
||||||
_perMessageDeflateOptions = perMessageDeflateOptions;
|
_perMessageDeflateOptions = perMessageDeflateOptions;
|
||||||
_enablePerMessageDeflate = _perMessageDeflateOptions.enabled();
|
_enablePerMessageDeflate = _perMessageDeflateOptions.enabled();
|
||||||
@ -109,11 +110,18 @@ namespace ix
|
|||||||
_pingTimeoutSecs = pingTimeoutSecs;
|
_pingTimeoutSecs = pingTimeoutSecs;
|
||||||
|
|
||||||
if (pingIntervalSecs > 0 && pingTimeoutSecs > 0)
|
if (pingIntervalSecs > 0 && pingTimeoutSecs > 0)
|
||||||
_pingIntervalOrTimeoutGCDSecs = greatestCommonDivisor(pingIntervalSecs, pingTimeoutSecs);
|
{
|
||||||
|
_pingIntervalOrTimeoutGCDSecs = greatestCommonDivisor(pingIntervalSecs,
|
||||||
|
pingTimeoutSecs);
|
||||||
|
}
|
||||||
else if (_pingTimeoutSecs > 0)
|
else if (_pingTimeoutSecs > 0)
|
||||||
|
{
|
||||||
_pingIntervalOrTimeoutGCDSecs = pingTimeoutSecs;
|
_pingIntervalOrTimeoutGCDSecs = pingTimeoutSecs;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
_pingIntervalOrTimeoutGCDSecs = pingIntervalSecs;
|
_pingIntervalOrTimeoutGCDSecs = pingIntervalSecs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
@ -236,13 +244,13 @@ namespace ix
|
|||||||
|
|
||||||
if (_readyState == OPEN)
|
if (_readyState == OPEN)
|
||||||
{
|
{
|
||||||
// if (1) ping timeout is enabled and (2) duration since last received ping response (PONG)
|
// if (1) ping timeout is enabled and (2) duration since last received
|
||||||
// exceeds the maximum delay, then close the connection
|
// ping response (PONG) exceeds the maximum delay, then close the connection
|
||||||
if (pingTimeoutExceeded())
|
if (pingTimeoutExceeded())
|
||||||
{
|
{
|
||||||
close(kInternalErrorCode, kPingTimeoutMessage);
|
close(kInternalErrorCode, kPingTimeoutMessage);
|
||||||
}
|
}
|
||||||
// If (1) ping is enabled and no ping has been sent for a duration
|
// If ping is enabled and no ping has been sent for a duration
|
||||||
// exceeding our ping interval, send a ping to the server.
|
// exceeding our ping interval, send a ping to the server.
|
||||||
else if (pingIntervalExceeded())
|
else if (pingIntervalExceeded())
|
||||||
{
|
{
|
||||||
@ -786,10 +794,9 @@ namespace ix
|
|||||||
WebSocketSendInfo WebSocketTransport::sendPing(const std::string& message)
|
WebSocketSendInfo WebSocketTransport::sendPing(const std::string& message)
|
||||||
{
|
{
|
||||||
bool compress = false;
|
bool compress = false;
|
||||||
|
|
||||||
WebSocketSendInfo info = sendData(wsheader_type::PING, message, compress);
|
WebSocketSendInfo info = sendData(wsheader_type::PING, message, compress);
|
||||||
|
|
||||||
if(info.success)
|
if (info.success)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lck(_lastSendPingTimePointMutex);
|
std::lock_guard<std::mutex> lck(_lastSendPingTimePointMutex);
|
||||||
_lastSendPingTimePoint = std::chrono::steady_clock::now();
|
_lastSendPingTimePoint = std::chrono::steady_clock::now();
|
||||||
|
@ -69,7 +69,8 @@ namespace ix
|
|||||||
|
|
||||||
void configure(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions,
|
void configure(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions,
|
||||||
bool enablePong,
|
bool enablePong,
|
||||||
int pingIntervalSecs, int pingTimeoutSecs);
|
int pingIntervalSecs,
|
||||||
|
int pingTimeoutSecs);
|
||||||
|
|
||||||
WebSocketInitResult connectToUrl(const std::string& url, // Client
|
WebSocketInitResult connectToUrl(const std::string& url, // Client
|
||||||
int timeoutSecs);
|
int timeoutSecs);
|
||||||
@ -162,24 +163,26 @@ namespace ix
|
|||||||
// Constants for dealing with closing conneections
|
// Constants for dealing with closing conneections
|
||||||
static const uint16_t kInternalErrorCode;
|
static const uint16_t kInternalErrorCode;
|
||||||
static const uint16_t kAbnormalCloseCode;
|
static const uint16_t kAbnormalCloseCode;
|
||||||
const static std::string kInternalErrorMessage;
|
static const std::string kInternalErrorMessage;
|
||||||
const static std::string kAbnormalCloseMessage;
|
static const std::string kAbnormalCloseMessage;
|
||||||
const static std::string kPingTimeoutMessage;
|
static const std::string kPingTimeoutMessage;
|
||||||
|
|
||||||
// enable auto response to ping
|
// enable auto response to ping
|
||||||
bool _enablePong;
|
bool _enablePong;
|
||||||
static const bool kDefaultEnablePong;
|
static const bool kDefaultEnablePong;
|
||||||
|
|
||||||
// Optional ping and pong timeout
|
// Optional ping and pong timeout
|
||||||
|
// if both ping interval and timeout are set (> 0),
|
||||||
|
// then use GCD of these value to wait for the lowest time
|
||||||
int _pingIntervalSecs;
|
int _pingIntervalSecs;
|
||||||
int _pingTimeoutSecs;
|
int _pingTimeoutSecs;
|
||||||
int _pingIntervalOrTimeoutGCDSecs; // if both ping interval and timeout are set (> 0), then use GCD of these value to wait for the lowest time
|
int _pingIntervalOrTimeoutGCDSecs;
|
||||||
|
|
||||||
static const int kDefaultPingIntervalSecs;
|
static const int kDefaultPingIntervalSecs;
|
||||||
static const int kDefaultPingTimeoutSecs;
|
static const int kDefaultPingTimeoutSecs;
|
||||||
const static std::string kPingMessage;
|
static const std::string kPingMessage;
|
||||||
|
|
||||||
// We record when ping are being sent so that we can know when to send the next one, periodically
|
// We record when ping are being sent so that we can know when to send the next one
|
||||||
// We also record when pong are being sent as a reply to pings, to close the connections
|
// We also record when pong are being sent as a reply to pings, to close the connections
|
||||||
// if no pong were received sufficiently fast.
|
// if no pong were received sufficiently fast.
|
||||||
mutable std::mutex _lastSendPingTimePointMutex;
|
mutable std::mutex _lastSendPingTimePointMutex;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user