irccd
3.0.3
|
Abstract transport client class. More...
#include <transport_client.hpp>
Public Types | |
enum | state { state::authenticating, state::ready, state::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) |
Abstract transport client class.
This class is responsible of receiving/sending data.
using irccd::daemon::transport_client::handshake_handler = std::function<void (std::error_code)> |
Handler for handshaking.
|
strong |
|
noexcept |
Constructor.
server | the parent |
stream | the I/O stream |
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.
code | the error code |
command | the command name |
handler | the optional handler |
void irccd::daemon::transport_client::error | ( | std::error_code | code, |
stream::send_handler | handler = nullptr |
||
) |
Send an error code to the client.
code | the error code |
handler | the optional handler |
|
noexcept |
Get the current client state.
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.
void irccd::daemon::transport_client::read | ( | stream::recv_handler | handler | ) |
Start receiving if not closed.
Possible error codes:
handler | the handler |
|
noexcept |
Set the client state.
state | the new state |
void irccd::daemon::transport_client::success | ( | const std::string & | command, |
stream::send_handler | handler = nullptr |
||
) |
Convenient success message.
command | the command name |
handler | the optional handler |
void irccd::daemon::transport_client::write | ( | nlohmann::json | json, |
stream::send_handler | handler = nullptr |
||
) |
Start sending if not closed.
Possible error codes:
json | the json message |
handler | the optional handler |