Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
web::ng::Server Class Reference

Web server class. More...

#include <Server.hpp>

Inheritance diagram for web::ng::Server:
Collaboration diagram for web::ng::Server:

Public Types

using OnConnectCheck = std::function<std::expected<void, Response>(Connection const&)>
 Check to perform for each new client connection. The check takes client ip as input and returns a Response if the check failed. Response will be sent to the client and the connection will be closed.
 
using OnDisconnectHook = impl::ConnectionHandler::OnDisconnectHook
 Hook called when any connection disconnects.
 

Public Member Functions

 Server (boost::asio::io_context &ctx, boost::asio::ip::tcp::endpoint endpoint, std::optional< boost::asio::ssl::context > sslContext, ProcessingPolicy processingPolicy, std::optional< size_t > parallelRequestLimit, util::TagDecoratorFactory tagDecoratorFactory, std::optional< size_t > maxSubscriptionSendQueueSize, OnConnectCheck onConnectCheck, OnDisconnectHook onDisconnectHook)
 Construct a new Server object.
 
 Server (Server const &)=delete
 Copy constructor is deleted. The Server couldn't be copied.
 
 Server (Server &&)=default
 Move constructor is defaulted.
 
void onGet (std::string const &target, MessageHandler handler)
 Set handler for GET requests.
 
void onPost (std::string const &target, MessageHandler handler)
 Set handler for POST requests.
 
void onWs (MessageHandler handler)
 Set handler for WebSocket requests.
 
std::optional< std::string > run ()
 Run the server.
 
void stop (boost::asio::yield_context yield)
 Stop the server. This method will asynchronously sleep unless all the users are disconnected.
 
- Public Member Functions inherited from web::ng::ServerTag

Detailed Description

Web server class.

Constructor & Destructor Documentation

◆ Server()

web::ng::Server::Server ( boost::asio::io_context & ctx,
boost::asio::ip::tcp::endpoint endpoint,
std::optional< boost::asio::ssl::context > sslContext,
ProcessingPolicy processingPolicy,
std::optional< size_t > parallelRequestLimit,
util::TagDecoratorFactory tagDecoratorFactory,
std::optional< size_t > maxSubscriptionSendQueueSize,
OnConnectCheck onConnectCheck,
OnDisconnectHook onDisconnectHook )

Construct a new Server object.

Parameters
ctxThe boost::asio::io_context to use.
endpointThe endpoint to listen on.
sslContextThe SSL context to use (optional).
processingPolicyThe requests processing policy (parallel or sequential).
parallelRequestLimitThe limit of requests for one connection that can be processed in parallel. Only used if processingPolicy is parallel.
tagDecoratorFactoryThe tag decorator factory.
maxSubscriptionSendQueueSizeThe maximum size of the subscription send queue.
onConnectCheckThe check to perform on each connection.
onDisconnectHookThe hook to call on each disconnection.

Member Function Documentation

◆ onGet()

void web::ng::Server::onGet ( std::string const & target,
MessageHandler handler )

Set handler for GET requests.

Note
This method can't be called after run() is called.
Parameters
targetThe target of the request.
handlerThe handler to set.

◆ onPost()

void web::ng::Server::onPost ( std::string const & target,
MessageHandler handler )

Set handler for POST requests.

Note
This method can't be called after run() is called.
Parameters
targetThe target of the request.
handlerThe handler to set.

◆ onWs()

void web::ng::Server::onWs ( MessageHandler handler)

Set handler for WebSocket requests.

Note
This method can't be called after run() is called.
Parameters
handlerThe handler to set.

◆ run()

std::optional< std::string > web::ng::Server::run ( )

Run the server.

Returns
std::nullopt if the server started successfully, otherwise an error message.

◆ stop()

void web::ng::Server::stop ( boost::asio::yield_context yield)

Stop the server. This method will asynchronously sleep unless all the users are disconnected.

Note
Stopping the server cause graceful shutdown of all connections. And rejecting new connections.
Parameters
yieldThe coroutine context.

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