staticlib_pion  2.0.2
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Public Member Functions | Protected Attributes | List of all members
staticlib::pion::tcp_server Class Reference

Multi-threaded, asynchronous TCP server. More...

#include <staticlib/pion/tcp_server.hpp>

Inheritance diagram for staticlib::pion::tcp_server:
staticlib::pion::http_server

Public Member Functions

 tcp_server (const asio::ip::tcp::endpoint &endpoint, uint32_t number_of_threads)
 Protected constructor so that only derived objects may be created.
 tcp_server (const tcp_server &)
 Deleted copy constructor.
tcp_server & operator= (const tcp_server &)
 Deleted copy assignment operator.
virtual ~tcp_server () STATICLIB_NOEXCEPT
 Virtual destructor.
void start ()
 Starts listening for new connections.
void stop (bool wait_until_finished=false)
 Stops listening for new connections.
bool is_listening () const
 Returns true if the server is listening for connections.
virtual void handle_connection (tcp_connection_ptr &tcp_conn)
 Handles a new TCP connection; derived classes SHOULD override this since the default behavior does nothing.
asio::io_service & get_io_service ()
 Returns an async I/O service used to schedule work.
scheduler & get_scheduler ()
 Return active scheduler.

Protected Attributes

scheduler active_scheduler
 Reference to the active scheduler object used to manage worker threads.
asio::ip::tcp::acceptor tcp_acceptor
 Manages async TCP connections.
tcp_connection::ssl_context_type ssl_context
 Context used for SSL configuration.
std::condition_variable server_has_stopped
 Condition triggered when the server has stopped listening for connections.
std::condition_variable no_more_connections
 Condition triggered when the connection pool is empty.
std::set< tcp_connection_ptr > conn_pool
 Pool of active connections associated with this server.
asio::ip::tcp::endpoint tcp_endpoint
 TCP endpoint used to listen for new connections.
bool ssl_flag
 true if the server uses SSL to encrypt connections
bool listening
 Set to true when the server is listening for new connections.
std::mutex mutex
 Mutex to make class thread-safe.

Detailed Description

Multi-threaded, asynchronous TCP server.

Constructor & Destructor Documentation

staticlib::pion::tcp_server::tcp_server ( const asio::ip::tcp::endpoint &  endpoint,
uint32_t  number_of_threads 
)
inline

Protected constructor so that only derived objects may be created.

Parameters
endpointTCP endpoint used to listen for new connections (see ASIO docs)
staticlib::pion::tcp_server::tcp_server ( const tcp_server &  )

Deleted copy constructor.

virtual staticlib::pion::tcp_server::~tcp_server ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

asio::io_service& staticlib::pion::tcp_server::get_io_service ( )
inline

Returns an async I/O service used to schedule work.

Returns
asio service
scheduler& staticlib::pion::tcp_server::get_scheduler ( )
inline

Return active scheduler.

Returns
scheduler
virtual void staticlib::pion::tcp_server::handle_connection ( tcp_connection_ptr &  tcp_conn)
inlinevirtual

Handles a new TCP connection; derived classes SHOULD override this since the default behavior does nothing.

Parameters
tcp_connthe new TCP connection to handle
bool staticlib::pion::tcp_server::is_listening ( ) const
inline

Returns true if the server is listening for connections.

Returns
true if the server is listening for connections
tcp_server& staticlib::pion::tcp_server::operator= ( const tcp_server &  )

Deleted copy assignment operator.

void staticlib::pion::tcp_server::start ( )

Starts listening for new connections.

void staticlib::pion::tcp_server::stop ( bool  wait_until_finished = false)

Stops listening for new connections.

Parameters
wait_until_finishedif true, blocks until all pending connections have closed

Member Data Documentation

scheduler staticlib::pion::tcp_server::active_scheduler
protected

Reference to the active scheduler object used to manage worker threads.

std::set<tcp_connection_ptr> staticlib::pion::tcp_server::conn_pool
protected

Pool of active connections associated with this server.

bool staticlib::pion::tcp_server::listening
protected

Set to true when the server is listening for new connections.

std::mutex staticlib::pion::tcp_server::mutex
mutableprotected

Mutex to make class thread-safe.

std::condition_variable staticlib::pion::tcp_server::no_more_connections
protected

Condition triggered when the connection pool is empty.

std::condition_variable staticlib::pion::tcp_server::server_has_stopped
protected

Condition triggered when the server has stopped listening for connections.

tcp_connection::ssl_context_type staticlib::pion::tcp_server::ssl_context
protected

Context used for SSL configuration.

bool staticlib::pion::tcp_server::ssl_flag
protected

true if the server uses SSL to encrypt connections

asio::ip::tcp::acceptor staticlib::pion::tcp_server::tcp_acceptor
protected

Manages async TCP connections.

asio::ip::tcp::endpoint staticlib::pion::tcp_server::tcp_endpoint
protected

TCP endpoint used to listen for new connections.


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