Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
web::impl::WsBase< Derived, HandlerType > Class Template Reference

Web socket implementation. This class is the base class of the web socket session, it will handle the read and write operations. More...

#include <WsBase.hpp>

Inheritance diagram for web::impl::WsBase< Derived, HandlerType >:
Collaboration diagram for web::impl::WsBase< Derived, HandlerType >:

Public Member Functions

 WsBase (std::string ip, std::reference_wrapper< util::TagDecoratorFactory const > tagFactory, std::reference_wrapper< dosguard::DOSGuardInterface > dosGuard, std::shared_ptr< HandlerType > const &handler, boost::beast::flat_buffer &&buffer, std::uint32_t maxSendingQueueSize)
 
Derived< HandlerType > & derived ()
 
void doWrite ()
 
void onWrite (boost::system::error_code ec, std::size_t)
 
void maybeSendNext ()
 
void send (std::shared_ptr< std::string > msg) override
 Send a message to the client.
 
SubscriptionContextPtr makeSubscriptionContext (util::TagDecoratorFactory const &factory) override
 Get the subscription context for this connection.
 
void send (std::string &&msg, http::status) override
 Send a message to the client.
 
void run (http::request< http::string_body > req)
 Accept the session asynchroniously.
 
void onAccept (boost::beast::error_code ec)
 
void doRead ()
 
void onRead (boost::beast::error_code ec, std::size_t bytesTransferred)
 
- Public Member Functions inherited from web::ConnectionBase
 ConnectionBase (util::TagDecoratorFactory const &tagFactory, std::string ip)
 Create a new connection base.
 
bool dead ()
 Indicates whether the connection had an error and is considered dead.
 
bool isAdmin () const
 Indicates whether the connection has admin privileges.
 
- Public Member Functions inherited from util::Taggable
 Taggable (Taggable &&)=default
 
Taggableoperator= (Taggable &&)=default
 
BaseTagDecorator const & tag () const
 Getter for tag decorator.
 

Protected Member Functions

void wsFail (boost::beast::error_code ec, char const *what)
 
- Protected Member Functions inherited from util::Taggable
 Taggable (util::TagDecoratorFactory const &tagFactory)
 New Taggable from a specified factory.
 

Protected Attributes

util::Logger log_ {"WebServer"}
 
util::Logger perfLog_ {"Performance"}
 
- Protected Attributes inherited from web::ConnectionBase
boost::system::error_code ec_
 
bool isAdmin_ = false
 

Additional Inherited Members

- Public Attributes inherited from web::ConnectionBase
std::string const clientIp
 
bool upgraded = false
 

Detailed Description

template<template< typename > typename Derived, SomeServerHandler HandlerType>
class web::impl::WsBase< Derived, HandlerType >

Web socket implementation. This class is the base class of the web socket session, it will handle the read and write operations.

The write operation is via a queue, each write operation of this session will be sent in order. The write operation also supports shared_ptr of string, so the caller can keep the string alive until it is sent. It is useful when we have multiple sessions sending the same content.

Template Parameters
DerivedThe derived class
HandlerTypeThe handler type, will be called when a request is received.

Member Function Documentation

◆ makeSubscriptionContext()

template<template< typename > typename Derived, SomeServerHandler HandlerType>
SubscriptionContextPtr web::impl::WsBase< Derived, HandlerType >::makeSubscriptionContext ( util::TagDecoratorFactory const & factory)
inlineoverridevirtual

Get the subscription context for this connection.

Parameters
factoryTag TagDecoratorFactory to use to create the context.
Returns
The subscription context for this connection.

Implements web::ConnectionBase.

◆ send() [1/2]

template<template< typename > typename Derived, SomeServerHandler HandlerType>
void web::impl::WsBase< Derived, HandlerType >::send ( std::shared_ptr< std::string > msg)
inlineoverridevirtual

Send a message to the client.

Parameters
msgThe message to send, it will keep the string alive until it is sent. It is useful when we have multiple session sending the same content. Be aware that the message length will not be added to the DOSGuard from this function.

Reimplemented from web::ConnectionBase.

◆ send() [2/2]

template<template< typename > typename Derived, SomeServerHandler HandlerType>
void web::impl::WsBase< Derived, HandlerType >::send ( std::string && msg,
http::status  )
inlineoverridevirtual

Send a message to the client.

Parameters
msgThe message to send Send this message to the client. The message length will be added to the DOSGuard If the DOSGuard is triggered, the message will be modified to include a warning

Implements web::ConnectionBase.


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