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) {
68 if (flyingPings < maxFlyingPings) {
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 },
79 pingInterval);
80 }
81
83 }
virtual void setTimeout(const utils::Timeval &timeout)=0
const std::string & getConnectionName() const
static Timer intervalTimer(const std::function< void(const std::function< void()> &)> &dispatcher, const utils::Timeval &timeout)
Definition Timer.cpp:61
virtual core::socket::stream::SocketConnection * getSocketConnection() const =0
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 web::websocket::SubProtocol< SocketContextUpgradeT >::flyingPings, core::socket::stream::SocketConnection::getConnectionName(), web::websocket::SubProtocolContext::getSocketConnection(), web::websocket::SubProtocol< SocketContextUpgradeT >::name, web::websocket::SubProtocol< SocketContextUpgradeT >::pingTimer, web::websocket::SubProtocol< SocketContextUpgradeT >::sendClose(), web::websocket::SubProtocol< SocketContextUpgradeT >::sendPing(), and web::websocket::SubProtocol< SocketContextUpgradeT >::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 web::websocket::client::SubProtocol, and web::websocket::server::SubProtocol.

Definition at line 86 of file SubProtocol.hpp.

86 {
88 }
void cancel()
Definition Timer.cpp:84

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 << "': attach";
145
146 onConnected();
147 }
virtual void onConnected()=0

References core::socket::stream::SocketConnection::getConnectionName(), web::websocket::SubProtocolContext::getSocketConnection(), web::websocket::SubProtocol< SocketContextUpgradeT >::name, web::websocket::SubProtocol< SocketContextUpgradeT >::onConnected(), and web::websocket::SubProtocol< SocketContextUpgradeT >::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 << "': detached";
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(), web::websocket::SubProtocol< SocketContextUpgradeT >::getPayloadTotalRead(), web::websocket::SubProtocol< SocketContextUpgradeT >::getPayloadTotalSent(), web::websocket::SubProtocolContext::getSocketConnection(), web::websocket::SubProtocol< SocketContextUpgradeT >::name, web::websocket::SubProtocol< SocketContextUpgradeT >::onDisconnected(), and web::websocket::SubProtocol< SocketContextUpgradeT >::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 web::websocket::SubProtocol< SocketContextUpgradeT >::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 {
194 }
virtual std::string getOnlineDuration() const =0

References web::websocket::SubProtocolContext::getOnlineDuration(), and web::websocket::SubProtocol< SocketContextUpgradeT >::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 {
189 }
virtual std::string getOnlineSince() const =0

References web::websocket::SubProtocolContext::getOnlineSince(), and web::websocket::SubProtocol< SocketContextUpgradeT >::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 {
184 }
virtual std::size_t getPayloadTotalRead() const =0

References web::websocket::SubProtocolContext::getPayloadTotalRead(), and web::websocket::SubProtocol< SocketContextUpgradeT >::subProtocolContext.

Referenced by web::websocket::SubProtocol< SocketContextUpgradeT >::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 {
179 }
virtual std::size_t getPayloadTotalSent() const =0

References web::websocket::SubProtocolContext::getPayloadTotalSent(), and web::websocket::SubProtocol< SocketContextUpgradeT >::subProtocolContext.

Referenced by web::websocket::SubProtocol< SocketContextUpgradeT >::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 {
174 }

References web::websocket::SubProtocolContext::getSocketConnection(), and web::websocket::SubProtocol< SocketContextUpgradeT >::subProtocolContext.

Here is the call 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, and apps::websocket::subprotocol::echo::server::Echo.

Referenced by web::websocket::SubProtocol< SocketContextUpgradeT >::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, and apps::websocket::subprotocol::echo::server::Echo.

Referenced by web::websocket::SubProtocol< SocketContextUpgradeT >::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()

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

◆ onMessageError()

template<typename SocketContextUpgradeT >
virtual void web::websocket::SubProtocol< SocketContextUpgradeT >::onMessageError ( uint16_t  errnum)
privatepure virtual

◆ onMessageStart()

template<typename SocketContextUpgradeT >
virtual void web::websocket::SubProtocol< SocketContextUpgradeT >::onMessageStart ( int  opCode)
privatepure virtual

◆ 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 web::websocket::SubProtocol< SocketContextUpgradeT >::flyingPings, core::socket::stream::SocketConnection::getConnectionName(), web::websocket::SubProtocolContext::getSocketConnection(), web::websocket::SubProtocol< SocketContextUpgradeT >::name, and web::websocket::SubProtocol< SocketContextUpgradeT >::subProtocolContext.

Here is the call graph for this function:

◆ onSignal()

template<typename SocketContextUpgradeT >
virtual bool web::websocket::SubProtocol< SocketContextUpgradeT >::onSignal ( int  sig)
privatepure virtual

◆ 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 {
139 subProtocolContext->sendClose(statusCode, reason, reasonLength);
140 }
virtual void sendClose(uint16_t statusCode=1000, const char *reason=nullptr, std::size_t reasonLength=0)=0

References web::websocket::SubProtocolContext::sendClose(), and web::websocket::SubProtocol< SocketContextUpgradeT >::subProtocolContext.

Referenced by apps::websocket::subprotocol::echo::client::Echo::onSignal(), apps::websocket::subprotocol::echo::server::Echo::onSignal(), and web::websocket::SubProtocol< SocketContextUpgradeT >::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 {
92 subProtocolContext->sendMessage(2, message, messageLength);
93 }
virtual void sendMessage(uint8_t opCode, const char *message, std::size_t messageLength)=0

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

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 web::websocket::SubProtocol< SocketContextUpgradeT >::subProtocolContext.

Referenced by apps::websocket::subprotocol::echo::server::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 }
virtual void sendMessageEnd(const char *message, std::size_t messageLength)=0

References web::websocket::SubProtocolContext::sendMessageEnd(), and web::websocket::SubProtocol< SocketContextUpgradeT >::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 }
virtual void sendMessageFrame(const char *message, std::size_t messageLength)=0

References web::websocket::SubProtocolContext::sendMessageFrame(), and web::websocket::SubProtocol< SocketContextUpgradeT >::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 }
virtual void sendMessageStart(uint8_t opCode, const char *message, std::size_t messageLength)=0

References web::websocket::SubProtocolContext::sendMessageStart(), and web::websocket::SubProtocol< SocketContextUpgradeT >::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 web::websocket::SubProtocol< SocketContextUpgradeT >::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
134 subProtocolContext->sendPing(reason, reasonLength);
135 }
virtual void sendPing(const char *reason=nullptr, std::size_t reasonLength=0)=0

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

Referenced by web::websocket::SubProtocol< SocketContextUpgradeT >::SubProtocol().

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

Friends And Related Symbol Documentation

◆ 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

◆ name

◆ pingTimer

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

◆ subProtocolContext


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