A network server. More...
#include <ana.hpp>


Classes | |
| struct | client_proxy |
| A connected client's representative in the server side. More... | |
Public Member Functions | |
| virtual operation_id | send_all (boost::asio::const_buffer buffer, send_handler *handler, send_type type=COPY_BUFFER)=0 |
| Send a buffer to every connected client. | |
| virtual operation_id | send_if (boost::asio::const_buffer buffer, send_handler *handler, const client_predicate &predicate, send_type type=COPY_BUFFER)=0 |
| Send a buffer to every connected client that satisfies a given condition/property. | |
| virtual operation_id | send_all_except (net_id except_id, boost::asio::const_buffer buffer, send_handler *handler, send_type type=COPY_BUFFER)=0 |
| Send a buffer to every connected client except one. | |
| virtual operation_id | send_one (net_id id, boost::asio::const_buffer buffer, send_handler *handler, send_type type=COPY_BUFFER)=0 |
| Send a buffer to a connected client with a given net_id. | |
| virtual void | set_connection_handler (connection_handler *)=0 |
| Set the handler for new connection events. | |
| virtual void | run (port port)=0 |
| Start the server on a given port. | |
| virtual void | disconnect (net_id id)=0 |
| Disconnect a connected client by force. | |
| virtual void | set_header_first_mode (net_id id)=0 |
| Set a client to header-first mode. | |
| virtual void | set_raw_data_mode (net_id id)=0 |
| Set a client to raw-data mode. | |
| virtual void | cancel_pending ()=0 |
| Cancel all pending network operations. | |
| virtual void | cancel_pending (ana::net_id client_id)=0 |
| Cancel all pending network operations for a given client. | |
| virtual std::string | ip_address (net_id) const =0 |
| Returns the string representing the ip address of a connected client. | |
| virtual const stats * | get_client_stats (net_id, stat_type) const =0 |
| Returns a pointer to an ana::stats object of a connected client. | |
| virtual void | expecting_message (net_id, size_t ms_until_timeout)=0 |
| Signal the server that you are waiting for a message from a given client in a certain period of time. | |
| virtual | ~server () |
| Standard destructor. | |
Static Public Member Functions | |
| static server * | create () |
| Creates an ana server. | |
A network server.
An object of this type can handle several connected clients.
Definition at line 343 of file ana.hpp.
| virtual ana::server::~server | ( | ) | [inline, virtual] |
| virtual void ana::server::cancel_pending | ( | ) | [pure virtual] |
Cancel all pending network operations.
Every pending operation handler will be invoked with ana::operation_aborted as the corresponding error_code, except that the error code will be boost::asio::error::operation_not_supported when run on Windows XP, Windows Server 2003, and earlier versions of Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined.
| virtual void ana::server::cancel_pending | ( | ana::net_id | client_id | ) | [pure virtual] |
Cancel all pending network operations for a given client.
Does nothing if the client_id doesn't belong to a connected client. Every pending operation handler will be invoked with ana::operation_aborted as the corresponding error_code.
| client_id | : Network ID of the client. |
| server * server::create | ( | ) | [static] |
Creates an ana server.
Examples:
Definition at line 91 of file asio_server.cpp.
| virtual void ana::server::disconnect | ( | net_id | id | ) | [pure virtual] |
Disconnect a connected client by force.
| id | : The net_id of the connected client. |
Referenced by ana_handshake_finisher_handler::handle_send().

| virtual void ana::server::expecting_message | ( | net_id | , | |
| size_t | ms_until_timeout | |||
| ) | [pure virtual] |
Signal the server that you are waiting for a message from a given client in a certain period of time.
The time parameter indicates how long you are willing to wait.
If a message is received before this time period then this call will be insignificant. However, if no such message is received, the appropriate call to handle_receive will be made with ana::timeout_error as the error_code parameter.
| id | : The ana::net_id of the client you are expecting the message from. If the id is invalid, this call will have no effect. | |
| time | : The amount of time you are willing to wait. |
Use the methods described in the ana::time namespace to create time lapses.
Examples:
Returns a pointer to an ana::stats object of a connected client.
| virtual std::string ana::server::ip_address | ( | net_id | ) | const [pure virtual] |
Returns the string representing the ip address of a connected client.
| virtual void ana::server::run | ( | port | port | ) | [pure virtual] |
Start the server on a given port.
Each time you call this method, a new thread will be started on the io_service object from asio. This means that it is possible to have multiple threads running the service, thus more threads will be able to run the handlers you implement.
The drawback is, however, that if you run the service on multiple threads, then you must be aware that the execution of your handlers may occur concurrently and thus you have to prevent all of the troubles arising from this concurrency.
Note that if you just call this method once, then you ensure mutual exclusion between your handlers, just make sure you don't block waiting for a call to a handler from one of your handlers, otherwise you'll always get a deadlock.
| port | : The port to be used for the server incoming connections. The port shouldn't be currently occupied. |
| virtual operation_id ana::server::send_all | ( | boost::asio::const_buffer | buffer, | |
| send_handler * | handler, | |||
| send_type | type = COPY_BUFFER | |||
| ) | [pure virtual] |
Send a buffer to every connected client.
| buffer | : Buffer to be sent. Should be constucted with the buffer function. | |
| handler | : Handler of events resulting from this operation. It will be called with _each_ event, meaning that it will be called exactly once for every connected client. | |
| send_type | : Optional, type of the send operation. Defaults to a value of COPY_BUFFER. |
Examples:
| virtual operation_id ana::server::send_all_except | ( | net_id | except_id, | |
| boost::asio::const_buffer | buffer, | |||
| send_handler * | handler, | |||
| send_type | type = COPY_BUFFER | |||
| ) | [pure virtual] |
Send a buffer to every connected client except one.
Equals a send_all if the client doesn't exist.
| buffer | : Buffer to be sent. Should be constucted with the buffer function. | |
| handler | : Handler of a possible event resulting from this operation. | |
| send_type | : Optional, type of the send operation. Defaults to COPY_BUFFER. |
Examples:
| virtual operation_id ana::server::send_if | ( | boost::asio::const_buffer | buffer, | |
| send_handler * | handler, | |||
| const client_predicate & | predicate, | |||
| send_type | type = COPY_BUFFER | |||
| ) | [pure virtual] |
Send a buffer to every connected client that satisfies a given condition/property.
| buffer | : Buffer to be sent. Should be constucted with the buffer function. | |
| handler | : Handler of events resulting from this operation. It will be called exactly once for every client that holds the property. | |
| send_type | : Optional, type of the send operation. Defaults to COPY_BUFFER. |
Examples:
| virtual operation_id ana::server::send_one | ( | net_id | id, | |
| boost::asio::const_buffer | buffer, | |||
| send_handler * | handler, | |||
| send_type | type = COPY_BUFFER | |||
| ) | [pure virtual] |
Send a buffer to a connected client with a given net_id.
Does nothing if no such client exists.
| buffer | : Buffer to be sent. Should be constucted with the buffer function. | |
| handler | : Handler of a possible event resulting from this operation. | |
| send_type | : Optional, type of the send operation. Defaults to COPY_BUFFER. |
Examples:
| virtual void ana::server::set_connection_handler | ( | connection_handler * | ) | [pure virtual] |
Set the handler for new connection events.
Referenced by ana_network_manager::create_server().

| virtual void ana::server::set_header_first_mode | ( | net_id | id | ) | [pure virtual] |
Set a client to header-first mode.
| virtual void ana::server::set_raw_data_mode | ( | net_id | id | ) | [pure virtual] |
Set a client to raw-data mode.
Referenced by ana_network_manager::create_server().

| Generated by doxygen 1.7.1 on Fri May 25 2012 01:18:00 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |