Public Member Functions | Static Public Member Functions

ana::client Struct Reference

A network client. More...

#include <ana.hpp>

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

List of all members.

Public Member Functions

virtual void connect (connection_handler *)=0
 Attempt a connection to the server.
virtual void connect_through_proxy (std::string proxy_address, std::string proxy_port, connection_handler *handler, std::string user_name="", std::string password="")=0
 Attempt a connection to the server through a proxy.
virtual void run ()=0
 Run the client listener, starts listening for incoming messages.
virtual operation_id send (boost::asio::const_buffer buffer, send_handler *handler, send_type type=COPY_BUFFER)=0
 Send a buffer or memory portion to the server.
virtual void cancel_pending ()=0
 Cancel all pending network operations.
virtual void expecting_message (size_t ms_until_timeout)=0
 Signal the client that you are waiting for a message from the server before a given time.
virtual void set_connect_timeout (size_t ms)=0
 Set a timeout value for connection attempts.
virtual std::string ip_address () const =0
 Returns the string representing the ip address of the connected client.
virtual ~client ()
 Standard destructor.

Static Public Member Functions

static clientcreate (address address, port port)
 Creates a client.

Detailed Description

A network client.

See also:
listener
sender

Definition at line 626 of file ana.hpp.


Constructor & Destructor Documentation

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

Standard destructor.

Definition at line 746 of file ana.hpp.


Member Function Documentation

virtual void ana::client::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::client::connect ( connection_handler  )  [pure virtual]

Attempt a connection to the server.

Parameters:
handler : The handler of the connection event.
Returns:
: The unique operation id of the connect operation.
See also:
connection_handler

Referenced by ana_network_manager::create_client_and_connect().

Here is the caller graph for this function:

virtual void ana::client::connect_through_proxy ( std::string  proxy_address,
std::string  proxy_port,
connection_handler handler,
std::string  user_name = "",
std::string  password = "" 
) [pure virtual]

Attempt a connection to the server through a proxy.

Parameters:
handler : The handler of the connection event.
Returns:
: The unique operation id of the connect operation.
See also:
connection_handler

Referenced by ana_network_manager::create_client_and_connect().

Here is the caller graph for this function:

ana::client * ana::client::create ( ana::address  address,
ana::port  pt 
) [static]

Creates a client.

Parameters:
address : The network address of the server.
port : The network port of the server.

Definition at line 77 of file asio_client.cpp.

virtual void ana::client::expecting_message ( size_t  ms_until_timeout  )  [pure virtual]

Signal the client that you are waiting for a message from the server before a given 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.

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
virtual std::string ana::client::ip_address (  )  const [pure virtual]

Returns the string representing the ip address of the connected client.

virtual void ana::client::run (  )  [pure virtual]

Run the client listener, starts listening for incoming messages.

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.

Referenced by ana_network_manager::create_client_and_connect().

Here is the caller graph for this function:

virtual operation_id ana::client::send ( boost::asio::const_buffer  buffer,
send_handler handler,
send_type  type = COPY_BUFFER 
) [pure virtual]

Send a buffer or memory portion to the server.

Examples:

  • client_->send( ana::buffer( str ), this );
  • client_->send( ana::buffer( large_pod_array ), handler_object, ana::ZERO_COPY );
Parameters:
buffer : The buffer being sent.
handler : Handler of events resulting from this operation.
send_type : Optional, type of the send operation. Defaults to COPY_BUFFER.
Returns:
: The unique operation id of the send operation.
See also:
send_type
Buffer
send_handler

Referenced by ana_network_manager::create_client_and_connect().

Here is the caller graph for this function:

virtual void ana::client::set_connect_timeout ( size_t  ms  )  [pure virtual]

Set a timeout value for connection attempts.

If attempting to connect through a proxy this value will be used once for the whole connection attempt.

You should use the time lapse constructors in namespace ana::time:

  • ana::time::seconds(10)
  • ana::time::minutes(1)
See also:
ana::time

Referenced by ana_network_manager::create_client_and_connect().

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:01 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs