diff --git a/Source/websocket/WebSocketLink.h b/Source/websocket/WebSocketLink.h index babf7076c..98e3d2dac 100644 --- a/Source/websocket/WebSocketLink.h +++ b/Source/websocket/WebSocketLink.h @@ -35,6 +35,10 @@ namespace Web { CLOSE = 0x08, PING = 0x09, PONG = 0x0A, + // Reserved ranges + // 0x3-0x7 + // 0xB-0xF + // Following are outside reseved 4-bit ranges VIOLATION = 0x10, // e.g. a control package without a FIN flag TOO_BIG = 0x20, // Protocol max support for 2^16 message per chunk INCONSISTENT = 0x30 // e.g. Protocol defined as Text, but received a binary. @@ -182,13 +186,15 @@ namespace Web { class WebSocketLinkType { public: enum EnumlinkState : uint8_t { - WEBSERVER = 0x01, + WEBSERVICE = 0x01, UPGRADING = 0x02, WEBSOCKET = 0x04, SUSPENDED = 0x08, ACTIVITY = 0x10 }; + DEPRECATED constexpr static EnumlinkState WEBSERVER { EnumlinkState::WEBSERVICE }; + typedef WebSocketLinkType ParentClass; private: @@ -373,7 +379,7 @@ PUSH_WARNING(DISABLE_WARNING_THIS_IN_MEMBER_INITIALIZER_LIST) , _handler(binary, masking) , _parent(parent) , _adminLock() - , _state(WEBSERVER) + , _state(WEBSERVICE) , _serializerImpl(*this, queueSize) , _deserialiserImpl(*this, queueSize) , _path() @@ -390,7 +396,7 @@ PUSH_WARNING(DISABLE_WARNING_THIS_IN_MEMBER_INITIALIZER_LIST) , _handler(binary, masking) , _parent(parent) , _adminLock() - , _state(WEBSERVER) + , _state(WEBSERVICE) , _serializerImpl(*this, queueSize) , _deserialiserImpl(*this, allocator) , _path() @@ -419,7 +425,7 @@ POP_WARNING() } bool IsWebServer() const { - return ((State() & WEBSERVER) != 0); + return ((State() & WEBSERVICE) != 0); } bool IsUpgrading() const { @@ -477,6 +483,18 @@ POP_WARNING() ACTUALLINK::Trigger(); } + void Pong() + { + _pingFireTime = Core::Time::Now().Ticks(); + + _adminLock.Lock(); + + _handler.Pong(); + + _adminLock.Unlock(); + + ACTUALLINK::Trigger(); + } bool Masking() const { return (_handler.Masking()); @@ -775,7 +793,7 @@ POP_WARNING() // Multiple message might be coming in, protect the state before we make assumptions on it value. _adminLock.Lock(); - if ((_state & WEBSERVER) == 0) { + if ((_state & WEBSERVICE) == 0) { _webSocketMessage->ErrorCode = Web::STATUS_INTERNAL_SERVER_ERROR; _webSocketMessage->Message = _T("State of the link can not be upgraded."); } else { @@ -794,7 +812,7 @@ POP_WARNING() _parent.StateChange(); if (_webSocketMessage->ErrorCode != Web::STATUS_SWITCH_PROTOCOL) { - _state = (_state & 0xF0) | WEBSERVER; + _state = (_state & 0xF0) | WEBSERVICE; _path.clear(); _query.clear(); _protocol.Clear(); @@ -845,7 +863,7 @@ POP_WARNING() _adminLock.Lock(); - if ((_state & WEBSERVER) != 0) { + if ((_state & WEBSERVICE) != 0) { result = true; _state = (_state & 0xF0) | UPGRADING; _origin = (origin.empty() ? ACTUALLINK::LocalId() : origin); @@ -1076,6 +1094,10 @@ POP_WARNING() { _channel.Ping(); } + void Pong() + { + _channel.Pong(); + } void Trigger() { _channel.Trigger(); @@ -1272,6 +1294,10 @@ POP_WARNING() { _channel.Ping(); } + void Pong() + { + _channel.Pong(); + } virtual bool IsIdle() const = 0; virtual void StateChange() = 0; @@ -1430,6 +1456,10 @@ POP_WARNING() { _channel.Ping(); } + void Pong() + { + _channel.Pong(); + } virtual bool IsIdle() const = 0; virtual void StateChange() = 0;