SNode.C
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
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
 

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
65 sendMessage("Welcome to SimpleChat");
66 sendMessage("=====================");
67 }
void sendMessage(const char *message, std::size_t messageLength) const

References web::websocket::SubProtocol< SocketContextUpgradeT >::sendMessage().

Here is the call graph for this function:

◆ onDisconnected()

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

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

Definition at line 95 of file Echo.cpp.

95 {
96 VLOG(1) << "Echo disconnected:";
97 }

◆ 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 73 of file Echo.cpp.

73 {
74 data += std::string(chunk, chunkLen);
75
76 VLOG(2) << "Message Fragment: " << std::string(chunk, chunkLen);
77 }

References data.

◆ onMessageEnd()

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

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

Definition at line 79 of file Echo.cpp.

79 {
80 VLOG(1) << "Message Data: " << data;
81 /*
82 forEachClient([&data = this->data](SubProtocol* client) {
83 client->sendMessage(data);
84 });
85 */
87
88 data.clear();
89 }
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 91 of file Echo.cpp.

91 {
92 VLOG(1) << "Message error: " << errnum;
93 }

◆ onMessageStart()

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

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

Definition at line 69 of file Echo.cpp.

69 {
70 VLOG(2) << "Message Start - OpCode: " << opCode;
71 }

◆ onSignal()

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

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

Definition at line 99 of file Echo.cpp.

99 {
100 VLOG(1) << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig
101 << ")";
102
103 sendClose();
104
105 return false;
106 }
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: