irccd  3.0.3
Public Types | Public Member Functions | List of all members
irccd::daemon::transport_server Class Reference

Abstract transport server class. More...

#include <transport_server.hpp>

Inheritance diagram for irccd::daemon::transport_server:

Public Types

using client_set = std::unordered_set< std::shared_ptr< transport_client > >
 
using accept_handler = std::function< void(std::error_code, std::shared_ptr< transport_client >)>
 

Public Member Functions

 transport_server (std::unique_ptr< acceptor > acceptor) noexcept
 
auto get_clients () const noexcept -> const client_set &
 
auto get_clients () noexcept -> client_set &
 
auto get_password () const noexcept -> const std::string &
 
void set_password (std::string password) noexcept
 
void accept (accept_handler handler)
 

Detailed Description

Abstract transport server class.

The transport_server class is an abstract interface that waits for clients to connect and store them locally. It does not know the underlying implementation so derived classes may be implemented in any shape of form.

As only constraint the implementation must provide an asynchronous operation to avoid blocking the daemon.

The derived class only have to implement accept function which is only responsible of getting a client ready for I/O (receiving and sending), the transport_server does authentication and greeting by itself.

Accept procedure

The connection procedure looks like this:

|
v [error]
+-----------------------------+ +---------------------+
| asynchronous accept process |----------------->| client is discarded |
+-----------------------------+ +---------------------+
| ^
| [success] |
v |
+-----------------------------------------+ [error while sending] |
| sending irccd information to the client |------------------------>+
+-----------------------------------------+ |
| | |
| | [authentication required] |
| | |
| v [error or invalid password] |
| +-------------------------+ +------------+ |
| | wait for authentication |-------->| send error |-------->+
| +-------------------------+ +------------+ ^
| | |
| | [correct password] |
v v |
+---------------------------------------+ [incorrect] |
| client is added to the list and ready ]-------------------------- +
+---------------------------------------+

I/O procedures

Each client has a reference to its parent, since operations are asynchronous, they maintain their lifetime by themselve to update the parent list on errors.

See the following diagram:

o (transport_client::recv or send is called) o
| |
| [no operations in queue] | [operation in progress]
| v
| +---------------+
| | push in queue |
| +---------------+
|
|
| [pending operations in queue]
|<-----------------------------------------------+
| ^
| |
v [success] |
+-------------------------------+ +-------------------+
| asynchronous operation starts |---------->| handler is called |
+-------------------------------+ +-------------------+
|
v [error]
+--------------------------------------+
| handler is called with an error code |
+--------------------------------------+
|
v
+----------------------------------+
| client delete itself from parent |
+----------------------------------+
See also
transport_client
transport_service

Member Typedef Documentation

◆ accept_handler

using irccd::daemon::transport_server::accept_handler = std::function<void (std::error_code, std::shared_ptr<transport_client>)>

Accept completion handler.

◆ client_set

using irccd::daemon::transport_server::client_set = std::unordered_set<std::shared_ptr<transport_client> >

Set of clients.

Constructor & Destructor Documentation

◆ transport_server()

irccd::daemon::transport_server::transport_server ( std::unique_ptr< acceptor acceptor)
noexcept

Constructor.

Precondition
acceptor != nullptr
Parameters
acceptorthe stream acceptor

Member Function Documentation

◆ accept()

void irccd::daemon::transport_server::accept ( accept_handler  handler)

Accept a client.

Also perform greetings and authentication under the hood. On success, the client is added into the server and is ready to use.

Precondition
handler != nullptr
Parameters
handlerthe completion handler

◆ get_clients() [1/2]

auto irccd::daemon::transport_server::get_clients ( ) const -> const client_set &
noexcept

Get the clients.

Returns
the clients

◆ get_clients() [2/2]

auto irccd::daemon::transport_server::get_clients ( ) -> client_set &
noexcept

Overloaded function.

Returns
the clients

◆ get_password()

auto irccd::daemon::transport_server::get_password ( ) const -> const std::string &
noexcept

Get the current password, empty string means no password.

Returns
the password

◆ set_password()

void irccd::daemon::transport_server::set_password ( std::string  password)
noexcept

Set an optional password, empty string means no password.

Parameters
passwordthe password

The documentation for this class was generated from the following file:
irccd::js::duk::push
auto push(duk_context *ctx, T &&value) -> int
Definition: duk.hpp:270
irccd::daemon::transport_server::accept
void accept(accept_handler handler)
irccd
Parent namespace.
Definition: acceptor.hpp:43
irccd::daemon::irc::rpl::list
@ list