dbp::tcp_server Class Reference

TCP Server class. More...

#include <tcp_server.h>

Inheritance diagram for dbp::tcp_server:
Inheritance graph
[legend]
Collaboration diagram for dbp::tcp_server:
Collaboration graph
[legend]

List of all members.

Public Types

typedef delegate2< const
socket &, const socket
&, socket * > 
on_io_handler
typedef delegate3< const
socket &, std::istream
&, std::ostream &, void > 
on_connect_handler
typedef delegate1< socket &, void > on_disconnect_handler
typedef delegate3< const
socket &, std::istream
&, std::ostream &, bool > 
on_process_data_handler
typedef delegate1< const
dbp::exception &, void > 
on_exception_handler

Public Member Functions

 tcp_server (size_t worker_threads=2, size_t queue_size=32768)
 Constructor.
 ~tcp_server ()
 Destructor.
int timeout ()
 Get timeout value.
tcp_servertimeout (int value)
 Set timeout value.
void start (const std::string &bind="*:0")
 Start the server.
void stop ()
 Stop the server.
bool is_running ()
 Detect server status.
void on_create_io_handler (on_io_handler handler)
 Assign 'on_create_io' event handler.
void on_connect (on_connect_handler handler)
void on_disconnect (on_disconnect_handler handler)
void on_process_data (on_process_data_handler handler)
void on_exception (on_exception_handler handler)

Detailed Description

TCP Server class.

This class provides generic TCP server features: it listens on the address/port specified, accepts new connections and process them. All networking details are hidden from the user; the interaction with the client is doing by events.

The server is asynchronous and multithreaded: one thread is listening the port; working threads are deal with data. There is the pool of incoming connections - the maximum number of active clients.


Member Function Documentation

bool dbp::tcp_server::is_running (  ) 

Detect server status.

Returns:
true if the server is working, false if it's stopped.
void dbp::tcp_server::on_create_io_handler ( on_io_handler  handler  )  [inline]

Assign 'on_create_io' event handler.

Your class can assign the event handler to the tcp_server on_connect event. The handler is called by tcp_server class when the client connects to server.

Parameters:
handler the event handler delegate
See also:
Event-driven programming paradigm
void dbp::tcp_server::start ( const std::string &  bind = "*:0"  ) 

Start the server.

Starts the socket listening and processes the requests. The listening will completed on addresses and ports provided by bind parameter in the following format:

host:port;host:port;...

where host is IP address or host name to listen on, or '*' meaning any address and port is the port number, for example: "*:80;localhost:443". The zero port meaning random port available selected by OS.

Parameters:
bind the address(es) and port(s) to listen on
void dbp::tcp_server::stop (  ) 

Stop the server.

Signals to all working tasks to stop and shuts down the server.


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

 
Support This Project
SourceForge.net Logo