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

Abstract transport client class. More...

#include <transport_client.hpp>

Inheritance diagram for irccd::daemon::transport_client:

Public Types

enum class  state { authenticating , ready , closing }
 
using handshake_handler = std::function< void(std::error_code)>
 

Public Member Functions

 transport_client (std::weak_ptr< transport_server > server, std::shared_ptr< stream > stream) noexcept
 
auto get_state () const noexcept -> state
 
void set_state (state state) noexcept
 
void handshake (handshake_handler)
 
void read (stream::recv_handler handler)
 
void write (nlohmann::json json, stream::send_handler handler=nullptr)
 
void success (const std::string &command, stream::send_handler handler=nullptr)
 
void error (std::error_code code, stream::send_handler handler=nullptr)
 
void error (std::error_code code, std::string_view command, stream::send_handler handler=nullptr)
 

Detailed Description

Abstract transport client class.

This class is responsible of receiving/sending data.

Member Typedef Documentation

◆ handshake_handler

using irccd::daemon::transport_client::handshake_handler = std::function<void (std::error_code)>

Handler for handshaking.

Member Enumeration Documentation

◆ state

Client state.

Enumerator
authenticating 

client is authenticating

ready 

client is ready

closing 

client is closing

Constructor & Destructor Documentation

◆ transport_client()

irccd::daemon::transport_client::transport_client ( std::weak_ptr< transport_server server,
std::shared_ptr< stream stream 
)
noexcept

Constructor.

Precondition
stream != nullptr
Parameters
serverthe parent
streamthe I/O stream

Member Function Documentation

◆ error() [1/2]

void irccd::daemon::transport_client::error ( std::error_code  code,
std::string_view  command,
stream::send_handler  handler = nullptr 
)

Send an error code to the client.

Precondition
code is not 0
Parameters
codethe error code
commandthe command name
handlerthe optional handler
Note
If a write operation is running, it is postponed once ready.

◆ error() [2/2]

void irccd::daemon::transport_client::error ( std::error_code  code,
stream::send_handler  handler = nullptr 
)

Send an error code to the client.

Precondition
code is not 0
Parameters
codethe error code
handlerthe optional handler
Note
If a write operation is running, it is postponed once ready.

◆ get_state()

auto irccd::daemon::transport_client::get_state ( ) const -> state
noexcept

Get the current client state.

Returns
the state

◆ handshake()

void irccd::daemon::transport_client::handshake ( handshake_handler  )

Do greetings and authentication if required.

This function should be called after a new client has been accepted by a transport_server.

◆ read()

void irccd::daemon::transport_client::read ( stream::recv_handler  handler)

Start receiving if not closed.

Possible error codes:

  • std::errc::network_down in case of errors,
  • std::errc::invalid_argument if the JSON message is invalid,
  • std::errc::not_enough_memory in case of memory failure.
Precondition
handler != nullptr
Parameters
handlerthe handler
Warning
Another read operation MUST NOT be running.

◆ set_state()

void irccd::daemon::transport_client::set_state ( state  state)
noexcept

Set the client state.

Parameters
statethe new state

◆ success()

void irccd::daemon::transport_client::success ( const std::string &  command,
stream::send_handler  handler = nullptr 
)

Convenient success message.

Parameters
commandthe command name
handlerthe optional handler
Note
If a write operation is running, it is postponed once ready.

◆ write()

void irccd::daemon::transport_client::write ( nlohmann::json  json,
stream::send_handler  handler = nullptr 
)

Start sending if not closed.

Possible error codes:

  • boost::system::errc::network_down in case of errors,
Precondition
json.is_object()
Parameters
jsonthe json message
handlerthe optional handler
Note
If a write operation is running, it is postponed once ready.

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