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

#include <tcp_server.hpp>

Public Types

typedef std::function< bool(const std::shared_ptr< tcp_client > &)> on_new_connection_callback_t
 

Public Member Functions

 tcp_server (void)
 ctor
 
 ~tcp_server (void)
 dtor
 
 tcp_server (const tcp_server &)=delete
 copy ctor
 
tcp_serveroperator= (const tcp_server &)=delete
 assignment operator
 
bool operator== (const tcp_server &rhs) const
 
bool operator!= (const tcp_server &rhs) const
 
void start (const std::string &host, std::uint32_t port, const on_new_connection_callback_t &callback=nullptr)
 
void stop (bool wait_for_removal=false, bool recursive_wait_for_removal=true)
 
bool is_running (void) const
 
tcp_socketget_socket (void)
 
const tcp_socketget_socket (void) const
 
const std::shared_ptr< tacopie::io_service > & get_io_service (void) const
 
const std::list< std::shared_ptr< tacopie::tcp_client > > & get_clients (void) const
 

Detailed Description

tacopie::tcp_server is the class providing TCP Server features. The tcp_server works entirely asynchronously, waiting for the io_service to notify whenever a new client wished to connect.

Member Typedef Documentation

◆ on_new_connection_callback_t

typedef std::function<bool(const std::shared_ptr<tcp_client>&)> tacopie::tcp_server::on_new_connection_callback_t

callback called whenever a new client is connecting to the server

Takes as parameter a shared pointer to the tcp_client that wishes to connect Returning true means connection is handled by tcp_client wrapper and nothing will be done by tcp_server. Returning false means connection is handled by tcp_server, will be stored in an internal list and tcp_client disconection_handler overriden.

Member Function Documentation

◆ get_clients()

const std::list<std::shared_ptr<tacopie::tcp_client> >& tacopie::tcp_server::get_clients ( void  ) const
Returns
the list of tacopie::tcp_client connected to the server.

◆ get_io_service()

const std::shared_ptr<tacopie::io_service>& tacopie::tcp_server::get_io_service ( void  ) const
Returns
io service monitoring this tcp connection

◆ get_socket() [1/2]

tcp_socket& tacopie::tcp_server::get_socket ( void  )
Returns
the tacopie::tcp_socket associated to the server. (non-const version)

◆ get_socket() [2/2]

const tcp_socket& tacopie::tcp_server::get_socket ( void  ) const
Returns
the tacopie::tcp_socket associated to the server. (const version)

◆ is_running()

bool tacopie::tcp_server::is_running ( void  ) const
Returns
whether the server is currently running or not

◆ operator!=()

bool tacopie::tcp_server::operator!= ( const tcp_server rhs) const

comparison operator

Returns
true when the underlying sockets are different (different file descriptor or socket type).

◆ operator==()

bool tacopie::tcp_server::operator== ( const tcp_server rhs) const

comparison operator

Returns
true when the underlying sockets are the same (same file descriptor and socket type).

◆ start()

void tacopie::tcp_server::start ( const std::string &  host,
std::uint32_t  port,
const on_new_connection_callback_t callback = nullptr 
)

Start the tcp_server at the given host and port.

Parameters
hosthostname to be connected to
portport to be connected to
callbackcallback to be called on new connections (may be null, connections are then handled automatically by the tcp_server object)

◆ stop()

void tacopie::tcp_server::stop ( bool  wait_for_removal = false,
bool  recursive_wait_for_removal = true 
)

Disconnect the tcp_server if it was currently running.

Parameters
wait_for_removalWhen sets to true, disconnect blocks until the underlying TCP server has been effectively removed from the io_service and that all the underlying callbacks have completed.
recursive_wait_for_removalWhen sets to true and wait_for_removal is also set to true, blocks until all the underlying TCP client connected to the TCP server have been effectively removed from the io_service and that all the underlying callbacks have completed.

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