Cadabra
Computer algebra system for field theory problems
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
websocket_server Class Reference

#include <websocket_server.hh>

Classes

class  connection
 

Public Types

using id_type = std::size_t
 
using request_type = boost::beast::http::request< boost::beast::http::string_body >
 
using response_type = boost::beast::http::response< boost::beast::http::string_body >
 
using message_handler = std::function< void(id_type, const std::string &, const request_type &, const std::string &ip_address)>
 
using connect_handler = std::function< void(id_type)>
 
using disconnect_handler = std::function< void(id_type)>
 
using http_handler = std::function< void(request_type &, response_type &)>
 

Public Member Functions

 websocket_server ()=default
 
 websocket_server (uint16_t port)
 
 ~websocket_server ()
 
 websocket_server (const websocket_server &)=delete
 
websocket_serveroperator= (const websocket_server &)=delete
 
void listen (uint16_t port)
 
void set_message_handler (message_handler h)
 
void set_connect_handler (connect_handler h)
 
void set_disconnect_handler (disconnect_handler h)
 
void set_http_handler (http_handler h)
 
void run ()
 
void stop ()
 
void send (id_type id, const std::string &message)
 
void close (id_type id)
 
uint16_t get_local_port () const
 

Private Member Functions

void do_accept ()
 
void remove_connection (id_type id)
 

Private Attributes

boost::asio::io_context ioc_
 
std::optional< boost::asio::ip::tcp::acceptor > acceptor_
 
std::unordered_map< id_type, std::shared_ptr< connection > > connections_
 
id_type next_connection_id_ {0}
 
message_handler message_handler_
 
connect_handler connect_handler_
 
disconnect_handler disconnect_handler_
 
http_handler http_handler_
 

Member Typedef Documentation

◆ connect_handler

using websocket_server::connect_handler = std::function<void(id_type)>

◆ disconnect_handler

using websocket_server::disconnect_handler = std::function<void(id_type)>

◆ http_handler

◆ id_type

using websocket_server::id_type = std::size_t

◆ message_handler

using websocket_server::message_handler = std::function<void(id_type, const std::string&, const request_type&, const std::string& ip_address)>

◆ request_type

using websocket_server::request_type = boost::beast::http::request<boost::beast::http::string_body>

◆ response_type

using websocket_server::response_type = boost::beast::http::response<boost::beast::http::string_body>

Constructor & Destructor Documentation

◆ websocket_server() [1/3]

websocket_server::websocket_server ( )
default

◆ websocket_server() [2/3]

websocket_server::websocket_server ( uint16_t  port)
explicit

◆ ~websocket_server()

websocket_server::~websocket_server ( )

◆ websocket_server() [3/3]

websocket_server::websocket_server ( const websocket_server )
delete

Member Function Documentation

◆ close()

void websocket_server::close ( id_type  id)

◆ do_accept()

void websocket_server::do_accept ( )
private

◆ get_local_port()

uint16_t websocket_server::get_local_port ( ) const

◆ listen()

void websocket_server::listen ( uint16_t  port)

◆ operator=()

websocket_server& websocket_server::operator= ( const websocket_server )
delete

◆ remove_connection()

void websocket_server::remove_connection ( id_type  id)
private

◆ run()

void websocket_server::run ( )

◆ send()

void websocket_server::send ( id_type  id,
const std::string &  message 
)

◆ set_connect_handler()

void websocket_server::set_connect_handler ( connect_handler  h)

◆ set_disconnect_handler()

void websocket_server::set_disconnect_handler ( disconnect_handler  h)

◆ set_http_handler()

void websocket_server::set_http_handler ( http_handler  h)

◆ set_message_handler()

void websocket_server::set_message_handler ( message_handler  h)

◆ stop()

void websocket_server::stop ( )

Member Data Documentation

◆ acceptor_

std::optional<boost::asio::ip::tcp::acceptor> websocket_server::acceptor_
private

◆ connect_handler_

connect_handler websocket_server::connect_handler_
private

◆ connections_

std::unordered_map<id_type, std::shared_ptr<connection> > websocket_server::connections_
private

◆ disconnect_handler_

disconnect_handler websocket_server::disconnect_handler_
private

◆ http_handler_

http_handler websocket_server::http_handler_
private

◆ ioc_

boost::asio::io_context websocket_server::ioc_
private

◆ message_handler_

message_handler websocket_server::message_handler_
private

◆ next_connection_id_

id_type websocket_server::next_connection_id_ {0}
private

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