Ping timeout use constant (#36)

* use constant for ping timeout

* change close code types
This commit is contained in:
Kumamon38 2019-04-19 18:16:25 +02:00 committed by Benjamin Sergeant
parent 4eded01841
commit 309b5ee1b3
2 changed files with 7 additions and 5 deletions

View File

@ -69,10 +69,11 @@ namespace ix
const int WebSocketTransport::kDefaultPingTimeoutSecs(-1); const int WebSocketTransport::kDefaultPingTimeoutSecs(-1);
const bool WebSocketTransport::kDefaultEnablePong(true); const bool WebSocketTransport::kDefaultEnablePong(true);
constexpr size_t WebSocketTransport::kChunkSize; constexpr size_t WebSocketTransport::kChunkSize;
const int WebSocketTransport::kInternalErrorCode(1011); const uint16_t WebSocketTransport::kInternalErrorCode(1011);
const int WebSocketTransport::kAbnormalCloseCode(1006); const uint16_t WebSocketTransport::kAbnormalCloseCode(1006);
const std::string WebSocketTransport::kInternalErrorMessage("Internal error"); const std::string WebSocketTransport::kInternalErrorMessage("Internal error");
const std::string WebSocketTransport::kAbnormalCloseMessage("Abnormal closure"); const std::string WebSocketTransport::kAbnormalCloseMessage("Abnormal closure");
const std::string WebSocketTransport::kPingTimeoutMessage("Ping timeout");
WebSocketTransport::WebSocketTransport() : WebSocketTransport::WebSocketTransport() :
_useMask(true), _useMask(true),
@ -240,7 +241,7 @@ namespace ix
// exceeds the maximum delay, then close the connection // exceeds the maximum delay, then close the connection
if (pingTimeoutExceeded()) if (pingTimeoutExceeded())
{ {
close(1011, "Ping timeout"); close(kInternalErrorCode, kPingTimeoutMessage);
} }
// If (1) ping is enabled and no ping has been sent for a duration // If (1) 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.

View File

@ -160,10 +160,11 @@ namespace ix
std::atomic<bool> _requestInitCancellation; std::atomic<bool> _requestInitCancellation;
// Constants for dealing with closing conneections // Constants for dealing with closing conneections
static const int kInternalErrorCode; static const uint16_t kInternalErrorCode;
static const int kAbnormalCloseCode; static const uint16_t kAbnormalCloseCode;
const static std::string kInternalErrorMessage; const static std::string kInternalErrorMessage;
const static std::string kAbnormalCloseMessage; const static std::string kAbnormalCloseMessage;
const static std::string kPingTimeoutMessage;
// enable auto response to ping // enable auto response to ping
bool _enablePong; bool _enablePong;