RADLib
RADical C++ application framework
RADNet::RADProtocolSocket Class Reference

Protocol socket wrapper that frames RADTcpSocket byte streams. More...

#include <RADNet.h>

+ Inheritance diagram for RADNet::RADProtocolSocket:
+ Collaboration diagram for RADNet::RADProtocolSocket:

Public Member Functions

 RADProtocolSocket (RADCore::EventLoop &loop)
 Creates an unconnected protocol socket. More...
 
 RADProtocolSocket (RADCore::EventLoop &loop, std::shared_ptr< RADTcpSocket > socket)
 Wraps an accepted TCP socket. More...
 
 ~RADProtocolSocket () override
 Closes the socket. More...
 
bool connectToHost (const std::string &host, uint16_t port)
 Connects to host:port. More...
 
bool sendFrame (uint32_t messageId, const std::vector< uint8_t > &payload)
 Sends a frame. More...
 
bool sendFrame (const RADTcpFrame &frame)
 Sends a frame. More...
 
void close ()
 Closes the wrapped socket. More...
 
bool isOpen () const
 Returns true when the wrapped socket is open. More...
 
void setMaxPayloadBytes (uint32_t maxPayloadBytes)
 Sets maximum accepted payload size. More...
 
void handleReadyRead ()
 Internal TCP readyRead handler. More...
 
void handleError (std::string message)
 Internal TCP error handler. More...
 
void handleConnected ()
 Internal connected handler. More...
 
void handleDisconnected ()
 Internal disconnected handler. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Public Attributes

RADCore::Event< void(RADNet::RADTcpFrame) > frameReceived
 Raised when a full frame is received. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised on socket or framing errors. More...
 
RADCore::Event< void() > connected
 Raised when connected. More...
 
RADCore::Event< void() > disconnected
 Raised when disconnected. More...
 

Detailed Description

Protocol socket wrapper that frames RADTcpSocket byte streams.

Constructor & Destructor Documentation

◆ RADProtocolSocket() [1/2]

RADNet::RADProtocolSocket::RADProtocolSocket ( RADCore::EventLoop loop)
explicit

Creates an unconnected protocol socket.

◆ RADProtocolSocket() [2/2]

RADNet::RADProtocolSocket::RADProtocolSocket ( RADCore::EventLoop loop,
std::shared_ptr< RADTcpSocket socket 
)

Wraps an accepted TCP socket.

◆ ~RADProtocolSocket()

RADNet::RADProtocolSocket::~RADProtocolSocket ( )
override

Closes the socket.

Member Function Documentation

◆ close()

void RADNet::RADProtocolSocket::close ( )

Closes the wrapped socket.

◆ connectToHost()

bool RADNet::RADProtocolSocket::connectToHost ( const std::string &  host,
uint16_t  port 
)

Connects to host:port.

◆ handleConnected()

void RADNet::RADProtocolSocket::handleConnected ( )

Internal connected handler.

◆ handleDisconnected()

void RADNet::RADProtocolSocket::handleDisconnected ( )

Internal disconnected handler.

◆ handleError()

void RADNet::RADProtocolSocket::handleError ( std::string  message)

Internal TCP error handler.

◆ handleReadyRead()

void RADNet::RADProtocolSocket::handleReadyRead ( )

Internal TCP readyRead handler.

◆ isOpen()

bool RADNet::RADProtocolSocket::isOpen ( ) const

Returns true when the wrapped socket is open.

◆ sendFrame() [1/2]

bool RADNet::RADProtocolSocket::sendFrame ( const RADTcpFrame frame)

Sends a frame.

◆ sendFrame() [2/2]

bool RADNet::RADProtocolSocket::sendFrame ( uint32_t  messageId,
const std::vector< uint8_t > &  payload 
)

Sends a frame.

◆ setMaxPayloadBytes()

void RADNet::RADProtocolSocket::setMaxPayloadBytes ( uint32_t  maxPayloadBytes)

Sets maximum accepted payload size.

Member Data Documentation

◆ connected

RADCore::Event<void () > RADNet::RADProtocolSocket::connected

Raised when connected.

◆ disconnected

RADCore::Event<void () > RADNet::RADProtocolSocket::disconnected

Raised when disconnected.

◆ errorOccurred

RADCore::Event<void (std::string) > RADNet::RADProtocolSocket::errorOccurred

Raised on socket or framing errors.

◆ frameReceived

RADCore::Event<void (RADNet::RADTcpFrame) > RADNet::RADProtocolSocket::frameReceived

Raised when a full frame is received.


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