#include <tcp_client.hpp>
◆ async_read_callback_t
callback to be called on async read completion takes the read_result as a parameter
◆ async_write_callback_t
callback to be called on async write completion takes the write_result as a parameter
◆ disconnection_handler_t
disconnection handle called whenever a disconnection occured
◆ tcp_client() [1/3]
tacopie::tcp_client::tcp_client |
( |
std::uint32_t |
num_io_workers = 1 | ) |
|
◆ ~tcp_client()
tacopie::tcp_client::~tcp_client |
( |
void |
| ) |
|
◆ tcp_client() [2/3]
tacopie::tcp_client::tcp_client |
( |
tcp_socket && |
socket | ) |
|
|
explicit |
custom ctor build socket from existing socket
- Parameters
-
socket | tcp_socket instance to be used for building the client (socket will be moved) |
◆ tcp_client() [3/3]
tacopie::tcp_client::tcp_client |
( |
const tcp_client & |
| ) |
|
|
delete |
◆ async_read()
void tacopie::tcp_client::async_read |
( |
const read_request & |
request | ) |
|
async read operation
- Parameters
-
request | read request information |
◆ async_write()
void tacopie::tcp_client::async_write |
( |
const write_request & |
request | ) |
|
async write operation
- Parameters
-
request | write request information |
◆ call_disconnection_handler()
void tacopie::tcp_client::call_disconnection_handler |
( |
void |
| ) |
|
|
private |
Call the user-defined disconnection handler
◆ clear_read_requests()
void tacopie::tcp_client::clear_read_requests |
( |
void |
| ) |
|
|
private |
Clear pending read requests (basically empty the queue of read requests)
◆ clear_write_requests()
void tacopie::tcp_client::clear_write_requests |
( |
void |
| ) |
|
|
private |
Clear pending write requests (basically empty the queue of write requests)
◆ connect()
void tacopie::tcp_client::connect |
( |
const std::string & |
host, |
|
|
std::uint32_t |
port, |
|
|
std::uint32_t |
timeout_msecs = 0 |
|
) |
| |
Connect the socket to the remote server.
- Parameters
-
host | Hostname of the target server |
port | Port of the target server |
timeout_msecs | maximum time to connect (will block until connect succeed or timeout expire). 0 will block undefinitely. If timeout expires, connection fails |
◆ disconnect()
void tacopie::tcp_client::disconnect |
( |
bool |
wait_for_removal = false | ) |
|
Disconnect the tcp_client if it was currently connected.
- Parameters
-
wait_for_removal | When sets to true, disconnect blocks until the underlying TCP client has been effectively removed from the io_service and that all the underlying callbacks have completed. |
◆ get_host()
const std::string& tacopie::tcp_client::get_host |
( |
void |
| ) |
const |
- Returns
- the hostname associated with the underlying socket.
◆ get_io_service()
- Returns
- io service monitoring this tcp connection
◆ get_port()
std::uint32_t tacopie::tcp_client::get_port |
( |
void |
| ) |
const |
- Returns
- the port associated with the underlying socket.
◆ get_socket() [1/2]
◆ get_socket() [2/2]
◆ is_connected()
bool tacopie::tcp_client::is_connected |
( |
void |
| ) |
const |
- Returns
- whether the client is currently connected or not
◆ on_read_available()
void tacopie::tcp_client::on_read_available |
( |
fd_t |
fd | ) |
|
|
private |
io service read callback called by the io service whenever the socket is readable
- Parameters
-
fd | file description of the socket for which the read is available |
◆ on_write_available()
void tacopie::tcp_client::on_write_available |
( |
fd_t |
fd | ) |
|
|
private |
io service write callback called by the io service whenever the socket is writable
- Parameters
-
fd | file description of the socket for which the write is available |
◆ operator!=()
bool tacopie::tcp_client::operator!= |
( |
const tcp_client & |
rhs | ) |
const |
comparison operator
- Returns
- true when the underlying sockets are different (different file descriptor or socket type).
◆ operator=()
◆ operator==()
bool tacopie::tcp_client::operator== |
( |
const tcp_client & |
rhs | ) |
const |
comparison operator
- Returns
- true when the underlying sockets are the same (same file descriptor and socket type).
◆ process_read()
process read operations when available basically called whenever on_read_available is called and try to read from the socket handle possible case of failure and fill in the result
- Parameters
-
result | result of the read operation |
- Returns
- the callback to be executed (set in the read request) on read completion (may be null)
◆ process_write()
process write operations when available basically called whenever on_write_available is called and try to write to the socket handle possible case of failure and fill in the result
- Parameters
-
result | result of the write operation |
- Returns
- the callback to be executed (set in the write request) on read completion (may be null)
◆ set_on_disconnection_handler()
set on disconnection handler
- Parameters
-
disconnection_handler | the handler to be called on disconnection |
◆ m_disconnection_handler
◆ m_io_service
std::shared_ptr<io_service> tacopie::tcp_client::m_io_service |
|
private |
◆ m_is_connected
std::atomic<bool> tacopie::tcp_client::m_is_connected = ATOMIC_VAR_INIT(false) |
|
private |
whether the client is currently connected or not
◆ m_read_requests
std::queue<read_request> tacopie::tcp_client::m_read_requests |
|
private |
◆ m_read_requests_mtx
std::mutex tacopie::tcp_client::m_read_requests_mtx |
|
private |
read requests thread safety
◆ m_socket
◆ m_write_requests
◆ m_write_requests_mtx
std::mutex tacopie::tcp_client::m_write_requests_mtx |
|
private |
write requests thread safety
The documentation for this class was generated from the following file: