Tacopie  3.0.0
Tacopie is a TCP Client & Server C++11 library.
Classes | Public Types | Public Member Functions | List of all members
tacopie::tcp_client Class Reference

#include <tcp_client.hpp>

Classes

struct  read_request
 
struct  read_result
 
struct  write_request
 
struct  write_result
 

Public Types

typedef std::function< void(read_result &)> async_read_callback_t
 
typedef std::function< void(write_result &)> async_write_callback_t
 
typedef std::function< void()> disconnection_handler_t
 

Public Member Functions

 tcp_client (void)
 ctor & dtor
 
 tcp_client (tcp_socket &&socket)
 
 tcp_client (const tcp_client &)=delete
 copy ctor
 
tcp_clientoperator= (const tcp_client &)=delete
 assignment operator
 
bool operator== (const tcp_client &rhs) const
 
bool operator!= (const tcp_client &rhs) const
 
const std::string & get_host (void) const
 
std::uint32_t get_port (void) const
 
void connect (const std::string &host, std::uint32_t port, std::uint32_t timeout_msecs=0)
 
void disconnect (bool wait_for_removal=false)
 
bool is_connected (void) const
 
void async_read (const read_request &request)
 
void async_write (const write_request &request)
 
tacopie::tcp_socketget_socket (void)
 
const tacopie::tcp_socketget_socket (void) const
 
const std::shared_ptr< tacopie::io_service > & get_io_service (void) const
 
void set_on_disconnection_handler (const disconnection_handler_t &disconnection_handler)
 

Detailed Description

tacopie::tcp_server is the class providing TCP Client features. The tcp_client works entirely asynchronously

Member Typedef Documentation

◆ 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

typedef std::function<void()> tacopie::tcp_client::disconnection_handler_t

disconnection handle called whenever a disconnection occured

Constructor & Destructor Documentation

◆ tcp_client()

tacopie::tcp_client::tcp_client ( tcp_socket &&  socket)
explicit

custom ctor build socket from existing socket

Parameters
sockettcp_socket instance to be used for building the client (socket will be moved)

Member Function Documentation

◆ async_read()

void tacopie::tcp_client::async_read ( const read_request request)

async read operation

Parameters
requestread request information

◆ async_write()

void tacopie::tcp_client::async_write ( const write_request request)

async write operation

Parameters
requestwrite request information

◆ 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
hostHostname of the target server
portPort of the target server
timeout_msecsmaximum 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_removalWhen 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()

const std::shared_ptr<tacopie::io_service>& tacopie::tcp_client::get_io_service ( void  ) const
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]

tacopie::tcp_socket& tacopie::tcp_client::get_socket ( void  )
Returns
underlying tcp_socket (non-const version)

◆ get_socket() [2/2]

const tacopie::tcp_socket& tacopie::tcp_client::get_socket ( void  ) const
Returns
underlying tcp_socket (const version)

◆ is_connected()

bool tacopie::tcp_client::is_connected ( void  ) const
Returns
whether the client is currently connected or not

◆ 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==()

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).

◆ set_on_disconnection_handler()

void tacopie::tcp_client::set_on_disconnection_handler ( const disconnection_handler_t disconnection_handler)

set on disconnection handler

Parameters
disconnection_handlerthe handler to be called on disconnection

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