SNode.C
Loading...
Searching...
No Matches
web::websocket::SubProtocol< SocketContextUpgradeT > Class Template Referenceabstract

#include <SubProtocol.h>

Collaboration diagram for web::websocket::SubProtocol< SocketContextUpgradeT >:

Public Member Functions

 SubProtocol (SubProtocol &)=delete
 SubProtocol (SubProtocol &&)=delete
SubProtocoloperator= (SubProtocol &)=delete
SubProtocoloperator= (SubProtocol &&)=delete
void sendMessage (const char *message, std::size_t messageLength) const
void sendMessage (const std::string &message) const
void sendMessageStart (const char *message, std::size_t messageLength) const
void sendMessageStart (const std::string &message) const
void sendMessageFrame (const char *message, std::size_t messageLength) const
void sendMessageFrame (const std::string &message) const
void sendMessageEnd (const char *message, std::size_t messageLength) const
void sendMessageEnd (const std::string &message) const
void sendPing (const char *reason=nullptr, std::size_t reasonLength=0) const
void sendClose (uint16_t statusCode=1000, const char *reason=nullptr, std::size_t reasonLength=0)
const std::string & getName ()
core::socket::stream::SocketConnectiongetSocketConnection () const
std::size_t getPayloadTotalSent () const
std::size_t getPayloadTotalRead () const
std::string getOnlineSince () const
std::string getOnlineDuration () const

Protected Member Functions

 SubProtocol (SubProtocolContext *subProtocolContext, const std::string &name, int pingInterval=60, int maxFlyingPings=3)
virtual ~SubProtocol ()

Protected Attributes

SubProtocolContextsubProtocolContext

Private Types

using SocketContextUpgrade = SocketContextUpgradeT

Private Member Functions

void attach ()
void detach ()
virtual void onConnected ()=0
virtual void onDisconnected ()=0
virtual bool onSignal (int sig)=0
virtual void onMessageStart (int opCode)=0
virtual void onMessageData (const char *chunk, std::size_t chunkLen)=0
virtual void onMessageEnd ()=0
virtual void onMessageError (uint16_t errnum)=0
virtual void onPongReceived ()

Private Attributes

const std::string name
core::timer::Timer pingTimer
int flyingPings = 0

Friends

template<typename SubProtocolT, typename RequestT, typename ResponseT>
class web::websocket::SocketContextUpgrade

Detailed Description

template<typename SocketContextUpgradeT>
class web::websocket::SubProtocol< SocketContextUpgradeT >

Definition at line 68 of file SubProtocol.h.

Member Typedef Documentation

◆ SocketContextUpgrade

template<typename SocketContextUpgradeT>
using web::websocket::SubProtocol< SocketContextUpgradeT >::SocketContextUpgrade = SocketContextUpgradeT
private

Definition at line 77 of file SubProtocol.h.

Constructor & Destructor Documentation

◆ SubProtocol() [1/3]

template<typename SocketContextUpgradeT>
web::websocket::SubProtocol< SocketContextUpgradeT >::SubProtocol ( SubProtocol< SocketContextUpgradeT > & )
delete

◆ SubProtocol() [2/3]

template<typename SocketContextUpgradeT>
web::websocket::SubProtocol< SocketContextUpgradeT >::SubProtocol ( SubProtocol< SocketContextUpgradeT > && )
delete

◆ SubProtocol() [3/3]

template<typename SocketContextUpgrade>
web::websocket::SubProtocol< SocketContextUpgrade >::SubProtocol ( SubProtocolContext * subProtocolContext,
const std::string & name,
int pingInterval = 60,
int maxFlyingPings = 3 )
protected

Definition at line 59 of file SubProtocol.hpp.

63 : name(name)
65 if (pingInterval > 0) {
67 [this, maxFlyingPings](const std::function<void()>& stop) {
69 sendPing();
71 } else {
72 LOG(WARNING) << this->subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '"
73 << this->name << "': MaxFlyingPings exceeded - closing";
74
75 sendClose();
76 stop();
77 }
78 },
80 }
81
83 }
virtual void setTimeout(const utils::Timeval &timeout)=0
static Timer intervalTimer(const std::function< void(const std::function< void()> &)> &dispatcher, const utils::Timeval &timeout)
Definition Timer.cpp:61
core::socket::stream::SocketConnection * getSocketConnection() const
void sendPing(const char *reason=nullptr, std::size_t reasonLength=0) const
SubProtocolContext * subProtocolContext
void sendClose(uint16_t statusCode=1000, const char *reason=nullptr, std::size_t reasonLength=0)
core::timer::Timer pingTimer

References flyingPings, core::socket::stream::SocketConnection::getConnectionName(), getSocketConnection(), web::websocket::SubProtocolContext::getSocketConnection(), name, pingTimer, sendClose(), sendPing(), and subProtocolContext.

Referenced by web::websocket::server::SubProtocol::SubProtocol().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~SubProtocol()

Reimplemented in iot::mqtt::SubProtocol< web::websocket::client::SubProtocol >, iot::mqtt::SubProtocol< web::websocket::server::SubProtocol >, web::websocket::client::SubProtocol, and web::websocket::server::SubProtocol.

Definition at line 86 of file SubProtocol.hpp.

86 {
87 pingTimer.cancel();
88 }

References core::Timer::cancel(), and pingTimer.

Here is the call graph for this function:

Member Function Documentation

◆ attach()

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::attach ( )
private

Definition at line 143 of file SubProtocol.hpp.

143 {
144 LOG(DEBUG) << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': start";
145
146 onConnected();
147 }
virtual void onConnected()=0

References core::socket::stream::SocketConnection::getConnectionName(), web::websocket::SubProtocolContext::getSocketConnection(), name, onConnected(), and subProtocolContext.

Here is the call graph for this function:

◆ detach()

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::detach ( )
private

Definition at line 150 of file SubProtocol.hpp.

150 {
152
153 LOG(DEBUG) << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': stopped";
154
155 LOG(DEBUG) << " Total Payload sent: " << getPayloadTotalSent();
156 LOG(DEBUG) << " Total Payload processed: " << getPayloadTotalRead();
157 }
std::size_t getPayloadTotalSent() const
virtual void onDisconnected()=0
std::size_t getPayloadTotalRead() const

References core::socket::stream::SocketConnection::getConnectionName(), getPayloadTotalRead(), getPayloadTotalSent(), web::websocket::SubProtocolContext::getSocketConnection(), name, onDisconnected(), and subProtocolContext.

Here is the call graph for this function:

◆ getName()

template<typename SocketContextUpgrade>
const std::string & web::websocket::SubProtocol< SocketContextUpgrade >::getName ( )

Definition at line 167 of file SubProtocol.hpp.

167 {
168 return name;
169 }

References name.

Referenced by web::websocket::server::GroupsManager::subscribe().

Here is the caller graph for this function:

◆ getOnlineDuration()

template<typename SocketContextUpgrade>
std::string web::websocket::SubProtocol< SocketContextUpgrade >::getOnlineDuration ( ) const

Definition at line 192 of file SubProtocol.hpp.

192 {
193 return subProtocolContext->getOnlineDuration();
194 }

References web::websocket::SubProtocolContext::getOnlineDuration(), and subProtocolContext.

Here is the call graph for this function:

◆ getOnlineSince()

template<typename SocketContextUpgrade>
std::string web::websocket::SubProtocol< SocketContextUpgrade >::getOnlineSince ( ) const

Definition at line 187 of file SubProtocol.hpp.

187 {
188 return subProtocolContext->getOnlineSince();
189 }

References web::websocket::SubProtocolContext::getOnlineSince(), and subProtocolContext.

Here is the call graph for this function:

◆ getPayloadTotalRead()

template<typename SocketContextUpgrade>
std::size_t web::websocket::SubProtocol< SocketContextUpgrade >::getPayloadTotalRead ( ) const

Definition at line 182 of file SubProtocol.hpp.

182 {
183 return subProtocolContext->getPayloadTotalRead();
184 }

References web::websocket::SubProtocolContext::getPayloadTotalRead(), and subProtocolContext.

Referenced by detach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPayloadTotalSent()

template<typename SocketContextUpgrade>
std::size_t web::websocket::SubProtocol< SocketContextUpgrade >::getPayloadTotalSent ( ) const

Definition at line 177 of file SubProtocol.hpp.

177 {
178 return subProtocolContext->getPayloadTotalSent();
179 }

References web::websocket::SubProtocolContext::getPayloadTotalSent(), and subProtocolContext.

Referenced by detach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSocketConnection()

Definition at line 172 of file SubProtocol.hpp.

172 {
173 return subProtocolContext->getSocketConnection();
174 }

References web::websocket::SubProtocolContext::getSocketConnection(), and subProtocolContext.

Referenced by SubProtocol().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onConnected()

template<typename SocketContextUpgradeT>
virtual void web::websocket::SubProtocol< SocketContextUpgradeT >::onConnected ( )
privatepure virtual

Implemented in apps::websocket::subprotocol::echo::client::Echo, apps::websocket::subprotocol::echo::server::Echo, iot::mqtt::SubProtocol< web::websocket::client::SubProtocol >, and iot::mqtt::SubProtocol< web::websocket::server::SubProtocol >.

Referenced by attach().

Here is the caller graph for this function:

◆ onDisconnected()

template<typename SocketContextUpgradeT>
virtual void web::websocket::SubProtocol< SocketContextUpgradeT >::onDisconnected ( )
privatepure virtual

Implemented in apps::websocket::subprotocol::echo::client::Echo, apps::websocket::subprotocol::echo::server::Echo, iot::mqtt::SubProtocol< web::websocket::client::SubProtocol >, and iot::mqtt::SubProtocol< web::websocket::server::SubProtocol >.

Referenced by detach().

Here is the caller graph for this function:

◆ onMessageData()

template<typename SocketContextUpgradeT>
virtual void web::websocket::SubProtocol< SocketContextUpgradeT >::onMessageData ( const char * chunk,
std::size_t chunkLen )
privatepure virtual

◆ onMessageEnd()

◆ onMessageError()

◆ onMessageStart()

◆ onPongReceived()

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::onPongReceived ( )
privatevirtual

Definition at line 160 of file SubProtocol.hpp.

160 {
161 LOG(DEBUG) << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': Pong received";
162
163 flyingPings = 0;
164 }

References flyingPings, core::socket::stream::SocketConnection::getConnectionName(), web::websocket::SubProtocolContext::getSocketConnection(), name, and subProtocolContext.

Here is the call graph for this function:

◆ onSignal()

◆ operator=() [1/2]

template<typename SocketContextUpgradeT>
SubProtocol & web::websocket::SubProtocol< SocketContextUpgradeT >::operator= ( SubProtocol< SocketContextUpgradeT > && )
delete

◆ operator=() [2/2]

template<typename SocketContextUpgradeT>
SubProtocol & web::websocket::SubProtocol< SocketContextUpgradeT >::operator= ( SubProtocol< SocketContextUpgradeT > & )
delete

◆ sendClose()

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendClose ( uint16_t statusCode = 1000,
const char * reason = nullptr,
std::size_t reasonLength = 0 )

Definition at line 138 of file SubProtocol.hpp.

138 {
140 }

References web::websocket::SubProtocolContext::sendClose(), and subProtocolContext.

Referenced by apps::websocket::subprotocol::echo::client::Echo::onSignal(), apps::websocket::subprotocol::echo::server::Echo::onSignal(), and SubProtocol().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessage() [1/2]

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendMessage ( const char * message,
std::size_t messageLength ) const

Definition at line 91 of file SubProtocol.hpp.

91 {
93 }

References web::websocket::SubProtocolContext::sendMessage(), and subProtocolContext.

Referenced by web::websocket::server::GroupsManager::sendBroadcast().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessage() [2/2]

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendMessage ( const std::string & message) const

Definition at line 96 of file SubProtocol.hpp.

96 {
97 subProtocolContext->sendMessage(1, message.data(), message.length());
98 }

References web::websocket::SubProtocolContext::sendMessage(), and subProtocolContext.

Referenced by apps::websocket::subprotocol::echo::client::Echo::onConnected(), and web::websocket::server::GroupsManager::sendBroadcast().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessageEnd() [1/2]

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendMessageEnd ( const char * message,
std::size_t messageLength ) const

Definition at line 121 of file SubProtocol.hpp.

121 {
122 subProtocolContext->sendMessageEnd(message, messageLength);
123 }

References web::websocket::SubProtocolContext::sendMessageEnd(), and subProtocolContext.

Referenced by web::websocket::server::GroupsManager::sendBroadcastEnd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessageEnd() [2/2]

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendMessageEnd ( const std::string & message) const

Definition at line 126 of file SubProtocol.hpp.

126 {
127 sendMessageEnd(message.data(), message.length());
128 }
void sendMessageEnd(const char *message, std::size_t messageLength) const

◆ sendMessageFrame() [1/2]

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendMessageFrame ( const char * message,
std::size_t messageLength ) const

Definition at line 111 of file SubProtocol.hpp.

111 {
112 subProtocolContext->sendMessageFrame(message, messageLength);
113 }

References web::websocket::SubProtocolContext::sendMessageFrame(), and subProtocolContext.

Referenced by web::websocket::server::GroupsManager::sendBroadcastFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessageFrame() [2/2]

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendMessageFrame ( const std::string & message) const

Definition at line 116 of file SubProtocol.hpp.

116 {
117 sendMessageFrame(message.data(), message.length());
118 }
void sendMessageFrame(const char *message, std::size_t messageLength) const

◆ sendMessageStart() [1/2]

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendMessageStart ( const char * message,
std::size_t messageLength ) const

Definition at line 101 of file SubProtocol.hpp.

101 {
102 subProtocolContext->sendMessageStart(2, message, messageLength);
103 }

References web::websocket::SubProtocolContext::sendMessageStart(), and subProtocolContext.

Referenced by web::websocket::server::GroupsManager::sendBroadcastStart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessageStart() [2/2]

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendMessageStart ( const std::string & message) const

Definition at line 106 of file SubProtocol.hpp.

106 {
107 subProtocolContext->sendMessageStart(1, message.data(), message.length());
108 }

References web::websocket::SubProtocolContext::sendMessageStart(), and subProtocolContext.

Here is the call graph for this function:

◆ sendPing()

template<typename SocketContextUpgrade>
void web::websocket::SubProtocol< SocketContextUpgrade >::sendPing ( const char * reason = nullptr,
std::size_t reasonLength = 0 ) const

Definition at line 131 of file SubProtocol.hpp.

131 {
132 LOG(DEBUG) << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': Ping sent";
133
135 }

References core::socket::stream::SocketConnection::getConnectionName(), web::websocket::SubProtocolContext::getSocketConnection(), name, web::websocket::SubProtocolContext::sendPing(), and subProtocolContext.

Referenced by SubProtocol().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ web::websocket::SocketContextUpgrade

template<typename SocketContextUpgradeT>
template<typename SubProtocolT, typename RequestT, typename ResponseT>
friend class web::websocket::SocketContextUpgrade
friend

Definition at line 133 of file SubProtocol.h.

Member Data Documentation

◆ flyingPings

template<typename SocketContextUpgradeT>
int web::websocket::SubProtocol< SocketContextUpgradeT >::flyingPings = 0
private

Definition at line 130 of file SubProtocol.h.

Referenced by onPongReceived(), and SubProtocol().

◆ name

template<typename SocketContextUpgradeT>
const std::string web::websocket::SubProtocol< SocketContextUpgradeT >::name
private

Definition at line 123 of file SubProtocol.h.

Referenced by attach(), detach(), getName(), onPongReceived(), sendPing(), and SubProtocol().

◆ pingTimer

template<typename SocketContextUpgradeT>
core::timer::Timer web::websocket::SubProtocol< SocketContextUpgradeT >::pingTimer
private

Definition at line 129 of file SubProtocol.h.

Referenced by SubProtocol(), and ~SubProtocol().

◆ subProtocolContext


The documentation for this class was generated from the following files: