indentation / comestic changes
This commit is contained in:
parent
0dfc66f1c7
commit
d48bf9249b
@ -100,7 +100,8 @@ namespace ix
|
||||
|
||||
void WebSocketTransport::configure(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions,
|
||||
bool enablePong,
|
||||
int pingIntervalSecs, int pingTimeoutSecs)
|
||||
int pingIntervalSecs,
|
||||
int pingTimeoutSecs)
|
||||
{
|
||||
_perMessageDeflateOptions = perMessageDeflateOptions;
|
||||
_enablePerMessageDeflate = _perMessageDeflateOptions.enabled();
|
||||
@ -109,11 +110,18 @@ namespace ix
|
||||
_pingTimeoutSecs = pingTimeoutSecs;
|
||||
|
||||
if (pingIntervalSecs > 0 && pingTimeoutSecs > 0)
|
||||
_pingIntervalOrTimeoutGCDSecs = greatestCommonDivisor(pingIntervalSecs, pingTimeoutSecs);
|
||||
{
|
||||
_pingIntervalOrTimeoutGCDSecs = greatestCommonDivisor(pingIntervalSecs,
|
||||
pingTimeoutSecs);
|
||||
}
|
||||
else if (_pingTimeoutSecs > 0)
|
||||
{
|
||||
_pingIntervalOrTimeoutGCDSecs = pingTimeoutSecs;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pingIntervalOrTimeoutGCDSecs = pingIntervalSecs;
|
||||
}
|
||||
}
|
||||
|
||||
// Client
|
||||
@ -236,13 +244,13 @@ namespace ix
|
||||
|
||||
if (_readyState == OPEN)
|
||||
{
|
||||
// if (1) ping timeout is enabled and (2) duration since last received ping response (PONG)
|
||||
// exceeds the maximum delay, then close the connection
|
||||
// if (1) ping timeout is enabled and (2) duration since last received
|
||||
// ping response (PONG) exceeds the maximum delay, then close the connection
|
||||
if (pingTimeoutExceeded())
|
||||
{
|
||||
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.
|
||||
else if (pingIntervalExceeded())
|
||||
{
|
||||
@ -786,10 +794,9 @@ namespace ix
|
||||
WebSocketSendInfo WebSocketTransport::sendPing(const std::string& message)
|
||||
{
|
||||
bool compress = false;
|
||||
|
||||
WebSocketSendInfo info = sendData(wsheader_type::PING, message, compress);
|
||||
|
||||
if(info.success)
|
||||
if (info.success)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(_lastSendPingTimePointMutex);
|
||||
_lastSendPingTimePoint = std::chrono::steady_clock::now();
|
||||
|
@ -69,7 +69,8 @@ namespace ix
|
||||
|
||||
void configure(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions,
|
||||
bool enablePong,
|
||||
int pingIntervalSecs, int pingTimeoutSecs);
|
||||
int pingIntervalSecs,
|
||||
int pingTimeoutSecs);
|
||||
|
||||
WebSocketInitResult connectToUrl(const std::string& url, // Client
|
||||
int timeoutSecs);
|
||||
@ -162,24 +163,26 @@ namespace ix
|
||||
// Constants for dealing with closing conneections
|
||||
static const uint16_t kInternalErrorCode;
|
||||
static const uint16_t kAbnormalCloseCode;
|
||||
const static std::string kInternalErrorMessage;
|
||||
const static std::string kAbnormalCloseMessage;
|
||||
const static std::string kPingTimeoutMessage;
|
||||
static const std::string kInternalErrorMessage;
|
||||
static const std::string kAbnormalCloseMessage;
|
||||
static const std::string kPingTimeoutMessage;
|
||||
|
||||
// enable auto response to ping
|
||||
bool _enablePong;
|
||||
static const bool kDefaultEnablePong;
|
||||
|
||||
// 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 _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 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
|
||||
// if no pong were received sufficiently fast.
|
||||
mutable std::mutex _lastSendPingTimePointMutex;
|
||||
|
Loading…
x
Reference in New Issue
Block a user