SNode.C
Loading...
Searching...
No Matches
apps::websocket::subprotocol::echo::server::Echo Class Reference

#include <Echo.h>

Inheritance diagram for apps::websocket::subprotocol::echo::server::Echo:
Collaboration diagram for apps::websocket::subprotocol::echo::server::Echo:

Public Member Functions

 Echo (web::websocket::SubProtocolContext *socketContextUpgradeBase, const std::string &name)
 
- Public Member Functions inherited from web::websocket::server::SubProtocol
 ~SubProtocol () override
 
void subscribe (const std::string &group)
 
void sendBroadcast (const char *message, std::size_t messageLength, bool excludeSelf=false)
 
void sendBroadcast (const std::string &message, bool excludeSelf=false)
 
void sendBroadcastStart (const char *message, std::size_t messageLength, bool excludeSelf=false)
 
void sendBroadcastStart (const std::string &message, bool excludeSelf=false)
 
void sendBroadcastFrame (const char *message, std::size_t messageLength, bool excludeSelf=false)
 
void sendBroadcastFrame (const std::string &message, bool excludeSelf=false)
 
void sendBroadcastEnd (const char *message, std::size_t messageLength, bool excludeSelf=false)
 
void sendBroadcastEnd (const std::string &message, bool excludeSelf=false)
 
void forEachClient (const std::function< void(const SubProtocol *)> &sendToClient, bool excludeSelf=false)
 
- Public Member Functions inherited from web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >
 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
 

Private Member Functions

void onConnected () override
 
void onMessageStart (int opCode) override
 
void onMessageData (const char *chunk, std::size_t chunkLen) override
 
void onMessageEnd () override
 
void onMessageError (uint16_t errnum) override
 
void onDisconnected () override
 
bool onSignal (int sig) override
 

Private Attributes

std::string data
 

Additional Inherited Members

- Protected Member Functions inherited from web::websocket::server::SubProtocol
 SubProtocol (SubProtocolContext *subProtocolContext, const std::string &name, int pingInterval=0, int maxFlyingPings=3)
 
- Protected Member Functions inherited from web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >
 SubProtocol (SubProtocolContext *subProtocolContext, const std::string &name, int pingInterval=60, int maxFlyingPings=3)
 
- Protected Attributes inherited from web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >
SubProtocolContextsubProtocolContext
 

Detailed Description

Definition at line 61 of file Echo.h.

Constructor & Destructor Documentation

◆ Echo()

apps::websocket::subprotocol::echo::server::Echo::Echo ( web::websocket::SubProtocolContext socketContextUpgradeBase,
const std::string &  name 
)

Definition at line 58 of file Echo.cpp.

References web::websocket::server::SubProtocol::SubProtocol().

Referenced by apps::websocket::subprotocol::echo::server::EchoFactory::create().

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

Member Function Documentation

◆ onConnected()

void apps::websocket::subprotocol::echo::server::Echo::onConnected ( )
overrideprivatevirtual

Implements web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >.

Definition at line 62 of file Echo.cpp.

62 {
63 VLOG(1) << "Echo connected";
64 }

◆ onDisconnected()

void apps::websocket::subprotocol::echo::server::Echo::onDisconnected ( )
overrideprivatevirtual

Implements web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >.

Definition at line 93 of file Echo.cpp.

93 {
94 VLOG(1) << "Echo disconnected:";
95 }

◆ onMessageData()

void apps::websocket::subprotocol::echo::server::Echo::onMessageData ( const char *  chunk,
std::size_t  chunkLen 
)
overrideprivatevirtual

Implements web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >.

Definition at line 70 of file Echo.cpp.

70 {
71 data += std::string(chunk, chunkLen);
72
73 VLOG(2) << "Message Fragment: " << std::string(chunk, chunkLen);
74 }

References data.

◆ onMessageEnd()

void apps::websocket::subprotocol::echo::server::Echo::onMessageEnd ( )
overrideprivatevirtual

Implements web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >.

Definition at line 76 of file Echo.cpp.

76 {
77 VLOG(1) << "Message Data: " << data;
78
79 // Alternative
80 // forEachClient([&data = this->data](SubProtocol* client) {
81 // client->sendMessage(data);
82 // });
83
85
86 data.clear();
87 }
void sendBroadcast(const char *message, std::size_t messageLength, bool excludeSelf=false)

References data, and web::websocket::server::SubProtocol::sendBroadcast().

Here is the call graph for this function:

◆ onMessageError()

void apps::websocket::subprotocol::echo::server::Echo::onMessageError ( uint16_t  errnum)
overrideprivatevirtual

Implements web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >.

Definition at line 89 of file Echo.cpp.

89 {
90 VLOG(1) << "Message error: " << errnum;
91 }

◆ onMessageStart()

void apps::websocket::subprotocol::echo::server::Echo::onMessageStart ( int  opCode)
overrideprivatevirtual

Implements web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >.

Definition at line 66 of file Echo.cpp.

66 {
67 VLOG(2) << "Message Start - OpCode: " << opCode;
68 }

◆ onSignal()

bool apps::websocket::subprotocol::echo::server::Echo::onSignal ( int  sig)
overrideprivatevirtual

Implements web::websocket::SubProtocol< web::websocket::server::SocketContextUpgrade >.

Definition at line 97 of file Echo.cpp.

97 {
98 VLOG(1) << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig
99 << ")";
100
101 sendClose();
102
103 return false;
104 }
void sendClose(uint16_t statusCode=1000, const char *reason=nullptr, std::size_t reasonLength=0)
std::string sigabbrev_np(int sig)
Definition signal.cpp:59

References web::websocket::SubProtocol< SocketContextUpgradeT >::sendClose(), and utils::system::sigabbrev_np().

Here is the call graph for this function:

Member Data Documentation

◆ data

std::string apps::websocket::subprotocol::echo::server::Echo::data
private

Definition at line 74 of file Echo.h.

Referenced by onMessageData(), and onMessageEnd().


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