Classes | Public Member Functions | Static Public Member Functions

ana::server Struct Reference

A network server. More...

#include <ana.hpp>

Inheritance diagram for ana::server:
Inheritance graph
[legend]
Collaboration diagram for ana::server:
Collaboration graph
[legend]

List of all members.

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 statsget_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 servercreate ()
 Creates an ana server.

Detailed Description

A network server.

An object of this type can handle several connected clients.

Definition at line 343 of file ana.hpp.


Constructor & Destructor Documentation

virtual ana::server::~server (  )  [inline, virtual]

Standard destructor.

Definition at line 550 of file ana.hpp.


Member Function Documentation

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.

Parameters:
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.

Parameters:
id : The net_id of the connected client.
See also:
net_id

Referenced by ana_handshake_finisher_handler::handle_send().

Here is the caller graph for this function:

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.

Parameters:
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:

  • client->waiting_for_message( ana::time::seconds( 5 ) );
See also:
error_code
ana::time
virtual const stats* ana::server::get_client_stats ( net_id  ,
stat_type   
) const [pure virtual]

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.

Parameters:
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.

Parameters:
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:

  • server_->send_all( ana::buffer( str ), this );
  • server_->send_all( ana::buffer( large_pod_array ), handler_object, ana::ZERO_COPY );
Returns:
: The unique operation id of the send operation.
See also:
send_type
Buffer
send_handler
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.

Parameters:
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:

  • server_->send_all_except( client, ana::buffer( str ), this, ana::ZERO_COPY);
Returns:
: The unique operation id of the send operation.
See also:
send_type
Buffer
send_handler
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.

Parameters:
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:

  • server_->send_if( ana::buffer( str() ), this, create_predicate( boost::bind( std::not_equal_to<net_id>(), client, _1) ) );
Returns:
: The unique operation id of the send operation.
See also:
client_predicate
send_type
Buffer
send_handler
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.

Parameters:
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:

  • server_->send_one( client, ana::buffer( str ), this, ana::ZERO_COPY);
Returns:
: The unique operation id of the send operation.
See also:
send_type
Buffer
send_handler
virtual void ana::server::set_connection_handler ( connection_handler  )  [pure virtual]

Set the handler for new connection events.

See also:
connection_handler

Referenced by ana_network_manager::create_server().

Here is the caller graph for this function:

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

Here is the caller graph for this function:


The documentation for this struct was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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