ana/api/ana.hpp

Go to the documentation of this file.
00001 /* $Id: ana.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 
00003 /**
00004  * @file
00005  * @brief Main include file for application developers that wish to use ana.
00006  *
00007  * ana: Asynchronous Network API.
00008  * Copyright (C) 2010 - 2012 Guillermo Biset.
00009  *
00010  * This file is part of the ana project.
00011  *
00012  * Contents:       Main header file for ana providing the whole public API.
00013  *
00014  * System:         ana
00015  * Language:       C++
00016  *
00017  * Author:         Guillermo Biset
00018  * E-Mail:         billybiset AT gmail DOT com
00019  *
00020  * ana is free software: you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation, either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * ana is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with ana.  If not, see <http://www.gnu.org/licenses/>.
00032  *
00033  */
00034 
00035 #ifdef DOXYGEN_ENABLE_ANA_MAINPAGE
00036 /**
00037  * @mainpage ana: Asynchronous Network API
00038  *
00039  * @author Guillermo Biset
00040  *
00041  * @section intro Introduction
00042  *
00043  * ana is an API to develop simple server and client applications.
00044  *
00045  * @image html logo.svg
00046  *
00047  * This project is being carried out as part of a Google Summer of Code 2010
00048  * project to reimplement <A HREF="http://wesnoth.org"> Wesnoth</A>'s stack.
00049  *
00050  * The projects' source code can be found at:
00051  * <A HREF="http://svn.gna.org/viewcvs/wesnoth/trunk/src/ana/"> Wesnoth's repository </A>
00052  *
00053  * @section requirements Requirements
00054  * To compile ana, you need:
00055  *  - Boost, version 1.35 or newer
00056  */
00057 #endif
00058 
00059 #include <boost/cstdint.hpp>
00060 #include <boost/noncopyable.hpp>
00061 #include <boost/system/error_code.hpp>
00062 #include <boost/asio.hpp>
00063 #include <boost/thread.hpp>
00064 #include <boost/asio/detail/socket_ops.hpp>
00065 
00066 #include <string>
00067 #include <cstdlib>
00068 #include <ctime>
00069 
00070 #ifndef ANA_HPP
00071 #define ANA_HPP
00072 
00073 #include "common.hpp"               //Main definitions
00074 #include "timers.hpp"               //Timer related
00075 #include "stats.hpp"                //Network statistics
00076 #include "predicates.hpp"           //Client predicates, used for conditional sending
00077 #include "binary_streams.hpp"       //For serialization
00078 
00079 /** @namespace ana
00080  *
00081  * Namespace for project ana, the entire API is under this namespce.
00082  */
00083 namespace ana
00084 {
00085     /** @name Miscellaneous Functions
00086      *
00087      * Functions for data conversions.
00088      */
00089     //@{
00090     /** Converts a 32 bit number in network byte order to a local number. */
00091     inline void network_to_host_long(ana_uint32& value)
00092     {
00093         value = ntohl(value);
00094     }
00095     /** Converts a 32 bit number into a network byte order number. */
00096     inline void host_to_network_long(ana_uint32& value)
00097     {
00098         value = htonl(value);
00099     }
00100     /** Converts a 16 bit number in network byte order to a local number. */
00101     inline void network_to_host_short(ana_uint16& value)
00102     {
00103         value = ntohs(value);
00104     }
00105     /** Converts a 16 bit number into a network byte order number. */
00106     inline void host_to_network_short(ana_uint16& value)
00107     {
00108         value = htons(value);
00109     }
00110     //@}
00111 
00112     /** @name Handler Interfaces
00113      *
00114      * Interfaces to handle network events.
00115      */
00116     //@{
00117     /**
00118      * Class that should be implemented to handle incoming messages or disconnections.
00119      */
00120     struct listener_handler
00121     {
00122         virtual ~listener_handler() {}
00123 
00124         /**
00125          * Handle an incoming message event.
00126          *
00127          * @param error_code : Error code of the client sending the message,
00128          *                     if it evaluates to false, then no error occurred.
00129          * @param net_id  : ID of the client that sends the message.
00130          * @param shared_buffer : The buffer from the incoming message.
00131          *
00132          * \sa read_buffer
00133          * \sa error_code
00134          * \sa net_id
00135          */
00136         virtual void handle_receive   (error_code, net_id, read_buffer) = 0;
00137 
00138         /**
00139          * Handle a disconnect event.
00140          *
00141          * @param error_code : Error code of the disconnecting client, it could
00142          *                     shed some light into why it got disconnected.
00143          *
00144          * @param net_id  : ID of the client that gets disconnected.
00145          *
00146          * \sa error_code
00147          * \sa net_id
00148          */
00149         virtual void handle_disconnect(error_code, net_id) = 0;
00150     };
00151 
00152     /**
00153      * Interface for every component that logs network statistics.
00154      */
00155     struct network_stats_logger
00156     {
00157         virtual ~network_stats_logger() {}
00158 
00159         /**
00160          * Get the associated collected stats as per a stat_type.
00161          *
00162          * @param type : stat_type to be collected ( ACCUMULATED, SECONDS, MINUTES, HOURS, DAYS )
00163          *
00164          * @returns A const pointer to a stats object holding the stats.
00165          *
00166          * \sa stats
00167          * \sa stat_type
00168          */
00169         virtual const stats* get_stats( stat_type type = ACCUMULATED ) const = 0;
00170     };
00171 
00172     /** Used for implementation purposes. */
00173     namespace detail
00174     {
00175         /** Last issued net_id.  */
00176         static net_id last_net_id_ = 0;
00177 
00178         /** Base class of network components. */
00179         class ana_component
00180         {
00181             public:
00182                 virtual ~ana_component() {}
00183 
00184                 /**
00185                  * Get the ID of this component.
00186                  *
00187                  * @returns : ID of the network component represented by this object.
00188                  */
00189                 net_id id() const {return id_;}
00190 
00191                 /**
00192                  * Disconnect the component.
00193                  */
00194                 virtual void disconnect() = 0;
00195 
00196                 /**
00197                  * Enter Raw Data mode, ana won't prefix your packets with header information.
00198                  *
00199                  * This is good for handshake procedures or every time you know how much you are
00200                  * supposed to receive. Combine this mode with a listener that is reading things
00201                  * the right way.
00202                  *
00203                  * \sa listener
00204                  */
00205                 void set_raw_data_mode()     { raw_data_ = true;  }
00206 
00207                 /**
00208                  * Enter header first mode, ana will prefix anything you send with size information
00209                  * first, so the listener will inform a new packet has been received only after it
00210                  * receives the whole packet.
00211                  */
00212                 void set_header_first_mode() { raw_data_ = false; }
00213 
00214                 /** Returns true iff the sender is in raw data mode. */
00215                 bool raw_mode()    const {return raw_data_;   }
00216 
00217                 /** Returns false iff the sender is in raw data mode. */
00218                 bool header_mode() const {return ! raw_data_; }
00219 
00220                 /**
00221                  * Get associated stats_collector object.
00222                  *
00223                  * @returns A pointer to the associated stats_collector object,
00224                  *          NULL if not keeping stats.
00225                  *
00226                  * \sa stats_collector.
00227                  */
00228                 virtual ana::stats_collector& stats_collector() = 0;
00229 
00230             protected:
00231                 /** Initialize component, assign fresh id and sets header-first and async modes. */
00232                 ana_component() :
00233                     raw_data_( false ),
00234                     id_(++last_net_id_)
00235                 {
00236                 }
00237 
00238             private:
00239                 /** The component is in raw data mode.*/
00240                 bool raw_data_;
00241 
00242                 /** This component's net_id. */
00243                 const net_id     id_;
00244         };
00245 
00246         /**
00247          * Base class for any network entity that handles incoming messages.
00248          */
00249         class listener : public virtual network_stats_logger,
00250                          public virtual ana_component
00251         {
00252             public:
00253                 /**
00254                  * Sets the handler for incoming messages.
00255                  *
00256                  * @param listener : Pointer to the listener_handler object that will
00257                  *                   handle following incoming message events.
00258                  *
00259                  * \sa listener_handler
00260                  */
00261                 virtual void set_listener_handler( listener_handler* listener ) = 0;
00262 
00263                 /**
00264                  * Sets the size of raw buffer.
00265                  *
00266                  * @param size : The requested size for raw buffers.
00267                  *
00268                  * @pre : Parameter should be positive.
00269                  */
00270                 virtual void set_raw_buffer_max_size( size_t size ) = 0;
00271 
00272                 /**
00273                  * Block the caller waiting for an incoming message of a certain amount of bytes.
00274                  *
00275                  * @param bis : Binary stream where the data will be stored.
00276                  * @param size : The amount of bytes trying to be read.
00277                  */
00278                 virtual void wait_raw_object(ana::serializer::bistream& bis, size_t size) = 0;
00279 
00280                 /** Start listening for incoming messages. */
00281                 virtual void run_listener() = 0;
00282 
00283             protected:
00284                 listener() {}
00285         };
00286 
00287         /** Provides send option setting to network components. */
00288         struct sender : public timed_sender,
00289                         public virtual ana_component
00290         {
00291         };
00292     } //namespace detail
00293 
00294     /**
00295      * Class that should be implemented to handle new connection events.
00296      */
00297     struct connection_handler
00298     {
00299         virtual ~connection_handler() {}
00300 
00301         /**
00302           * Handle new connection event.
00303           *
00304           * @param error_code : Error code of the event.
00305           *
00306           * @param net_id  : ID of the client that connects.
00307           *
00308           * \sa error_code
00309           * \sa net_id
00310           */
00311         virtual void handle_connect( error_code, net_id )  = 0;
00312     };
00313 
00314     /**
00315      * Class that should be implemented to handle send completion events.
00316      */
00317     struct send_handler
00318     {
00319         virtual ~send_handler() {}
00320 
00321         /**
00322          * Handle send completion event.
00323          *
00324          * @param error_code : Error code of the event.
00325          *
00326          * @param net_id  : ID of the client that sent the message.
00327          *
00328          * \sa error_code
00329          * \sa net_id
00330          */
00331         virtual void handle_send( error_code, net_id, operation_id ) = 0;
00332     };
00333     //@}
00334 
00335     /** @name Main classes.
00336      *
00337      * Main classes in ana.
00338      */
00339     //@{
00340     /**
00341      * A network server. An object of this type can handle several connected clients.
00342      */
00343     struct server : public virtual detail::listener,
00344                     public virtual detail::sender
00345     {
00346         /**
00347          * Creates an ana server.
00348          *
00349          * Examples:
00350          *     - ana::server* server = ana::server::create();
00351          */
00352         static server* create();
00353 
00354         /**
00355          * Send a buffer to every connected client.
00356          *
00357          * @param buffer : Buffer to be sent. Should be constucted with the buffer function.
00358          * @param handler : Handler of events resulting from this operation. It will be called
00359          *                  with _each_ event, meaning that it will be called exactly once
00360          *                  for every connected client.
00361          * @param send_type : Optional, type of the send operation.
00362          *                    Defaults to a value of COPY_BUFFER.
00363          *
00364          * Examples:
00365          *    - server_->send_all( ana::buffer( str ), this );
00366          *    - server_->send_all( ana::buffer( large_pod_array ), handler_object, ana::ZERO_COPY );
00367          *
00368          * @returns : The unique operation id of the send operation.
00369          *
00370          * \sa send_type
00371          * \sa buffer
00372          * \sa send_handler
00373          */
00374         virtual operation_id send_all(boost::asio::const_buffer buffer,
00375                                       send_handler*             handler,
00376                                       send_type                 type = COPY_BUFFER ) = 0;
00377 
00378         /**
00379          * Send a buffer to every connected client that satisfies a given condition/property.
00380          *
00381          * @param buffer : Buffer to be sent. Should be constucted with the buffer function.
00382          * @param handler : Handler of events resulting from this operation. It will be called
00383          *                  exactly once for every client that holds the property.
00384          * @param send_type : Optional, type of the send operation. Defaults to COPY_BUFFER.
00385          *
00386          * Examples:
00387          *  - server_->send_if( ana::buffer( str() ), this,
00388          *             create_predicate( boost::bind( std::not_equal_to<net_id>(), client, _1) ) );
00389          *
00390          * @returns : The unique operation id of the send operation.
00391          *
00392          * \sa client_predicate
00393          * \sa send_type
00394          * \sa buffer
00395          * \sa send_handler
00396          */
00397         virtual operation_id send_if(boost::asio::const_buffer buffer,
00398                                      send_handler*             handler,
00399                                      const client_predicate&   predicate,
00400                                      send_type                 type = COPY_BUFFER ) = 0;
00401 
00402         /**
00403          * Send a buffer to every connected client except one.
00404          * Equals a send_all if the client doesn't exist.
00405          *
00406          * @param buffer : Buffer to be sent. Should be constucted with the buffer function.
00407          * @param handler : Handler of a possible event resulting from this operation.
00408          * @param send_type : Optional, type of the send operation. Defaults to COPY_BUFFER.
00409          *
00410          * Examples:
00411          *    - server_->send_all_except( client, ana::buffer( str ), this, ana::ZERO_COPY);
00412          *
00413          * @returns : The unique operation id of the send operation.
00414          *
00415          * \sa send_type
00416          * \sa buffer
00417          * \sa send_handler
00418          */
00419         virtual operation_id send_all_except(net_id                    except_id,
00420                                              boost::asio::const_buffer buffer,
00421                                              send_handler*             handler,
00422                                              send_type                 type = COPY_BUFFER ) = 0;
00423 
00424         /**
00425          * Send a buffer to a connected client with a given net_id.
00426          * Does nothing if no such client exists.
00427          *
00428          * @param buffer : Buffer to be sent. Should be constucted with the buffer function.
00429          * @param handler : Handler of a possible event resulting from this operation.
00430          * @param send_type : Optional, type of the send operation. Defaults to COPY_BUFFER.
00431          *
00432          * Examples:
00433          *    - server_->send_one( client, ana::buffer( str ), this, ana::ZERO_COPY);
00434          *
00435          * @returns : The unique operation id of the send operation.
00436          *
00437          * \sa send_type
00438          * \sa buffer
00439          * \sa send_handler
00440          */
00441         virtual operation_id send_one(net_id                    id,
00442                                       boost::asio::const_buffer buffer,
00443                                       send_handler*             handler,
00444                                       send_type                 type = COPY_BUFFER ) = 0;
00445 
00446         /**
00447          * Set the handler for new connection events.
00448          *
00449          * \sa connection_handler
00450          */
00451         virtual void set_connection_handler( connection_handler* ) = 0;
00452 
00453         /**
00454          * Start the server on a given port.
00455          *
00456          * Each time you call this method, a new thread will be started on the io_service object
00457          * from asio. This means that it is possible to have multiple threads running the service,
00458          * thus more threads will be able to run the handlers you implement.
00459          *
00460          * The drawback is, however, that if you run the service on multiple threads, then you must
00461          * be aware that the execution of your handlers may occur concurrently and thus you have to
00462          * prevent all of the troubles arising from this concurrency.
00463          *
00464          * Note that if you just call this method once, then you ensure mutual exclusion between
00465          * your handlers, just make sure you don't block waiting for a call to a handler from one
00466          * of your handlers, otherwise you'll always get a deadlock.
00467          *
00468          * @param port : The port to be used for the server incoming connections.
00469          *               The port shouldn't be currently occupied.
00470          */
00471         virtual void run(port port)                                = 0;
00472 
00473         /**
00474          * Disconnect a connected client by force.
00475          *
00476          * @param id : The net_id of the connected client.
00477          *
00478          * \sa net_id
00479          */
00480         virtual void disconnect( net_id id )                       = 0;
00481 
00482         /** Set a client to header-first mode. */
00483         virtual void set_header_first_mode( net_id id )            = 0;
00484 
00485         /** Allow external object to call set_header_first_mode() directly. */
00486         using ana::detail::ana_component::set_header_first_mode;
00487 
00488         /** Set a client to raw-data mode.     */
00489         virtual void set_raw_data_mode( net_id id )                = 0;
00490 
00491         /**
00492          * Cancel all pending network operations.
00493          *
00494          * Every pending operation handler will be invoked with ana::operation_aborted
00495          * as the corresponding error_code, except that the error code will be
00496          * boost::asio::error::operation_not_supported when run on Windows XP,
00497          * Windows Server 2003, and earlier versions of Windows,
00498          * unless BOOST_ASIO_ENABLE_CANCELIO is defined.
00499          */
00500         virtual void cancel_pending( )                             = 0;
00501 
00502         /**
00503          * Cancel all pending network operations for a given client.
00504          * Does nothing if the client_id doesn't belong to a connected client.
00505          * Every pending operation handler will be invoked with ana::operation_aborted
00506          * as the corresponding error_code.
00507          *
00508          * @param client_id : Network ID of the client.
00509          */
00510         virtual void cancel_pending( ana::net_id client_id )       = 0;
00511 
00512         /* Allow external object to call set_raw_data_mode() directly. */
00513         /**
00514          * Set the server to raw data mode, every time a client connects
00515          * it will use the current mode.
00516          */
00517         using ana::detail::ana_component::set_raw_data_mode;
00518 
00519         /** Returns the string representing the ip address of a connected client. */
00520         virtual std::string ip_address( net_id ) const = 0;
00521 
00522         /** Returns a pointer to an ana::stats object of a connected client. */
00523         virtual const stats* get_client_stats( net_id, stat_type ) const = 0;
00524 
00525         /**
00526          * Signal the server that you are waiting for a message from a given client in a certain
00527          * period of time.
00528          *
00529          * The time parameter indicates how long you are willing to wait.
00530          *
00531          * If a message is received before this time period then this call will be insignificant.
00532          * However, if no such message is received, the appropriate call to handle_receive will be
00533          * made with ana::timeout_error as the error_code parameter.
00534          *
00535          * @param id : The ana::net_id of the client you are expecting the message from. If the
00536          *             id is invalid, this call will have no effect.
00537          * @param time : The amount of time you are willing to wait.
00538          *
00539          * Use the methods described in the ana::time namespace to create time lapses.
00540          *
00541          * Examples:
00542          *     - client->waiting_for_message( ana::time::seconds( 5 ) );
00543          *
00544          * @sa error_code
00545          * @sa ana::time
00546          */
00547         virtual void expecting_message( net_id, size_t ms_until_timeout ) = 0;
00548 
00549         /** Standard destructor. */
00550         virtual ~server() {}
00551 
00552         /**
00553          * A connected client's representative in the server side.
00554          */
00555         struct client_proxy : public virtual detail::listener,
00556                               public         detail::sender,
00557                               boost::noncopyable
00558         {
00559             /**
00560              * Send a buffer to the corresponding client.
00561              *
00562              * @param buffer : The memory portion or buffer being sent.
00563              * @param handler : The handler of the completion or error event.
00564              * @param sender : The object with the timeout configuration.
00565              *
00566              * \sa shared_buffer
00567              * \sa send_handler
00568              * \sa sender
00569              */
00570             virtual void send(detail::shared_buffer, send_handler*, sender*, operation_id ) = 0;
00571 
00572             /** Standard destructor. */
00573             virtual ~client_proxy() {}
00574 
00575             /**
00576              * Cancel all pending network operations.
00577              *
00578              * Every pending operation handler will be invoked with ana::operation_aborted
00579              * as the corresponding error_code, except that the error code will be
00580              * boost::asio::error::operation_not_supported when run on Windows XP,
00581              * Windows Server 2003, and earlier versions of Windows,
00582              * unless BOOST_ASIO_ENABLE_CANCELIO is defined.
00583              */
00584             virtual void cancel_pending() = 0;
00585 
00586             /** Returns the string representing the ip address of the connected client. */
00587             virtual std::string ip_address() const = 0;
00588 
00589             /**
00590              * Signal the client proxy that you are waiting for a message from the actual client
00591              * before a given time.
00592              *
00593              * The time parameter indicates how long you are willing to wait.
00594              *
00595              * If a message is received before this time period then this call will be
00596              * insignificant.
00597              * However, if no such message is received, the appropriate call to handle_receive will
00598              * be made with ana::timeout_error as the error_code parameter.
00599              *
00600              * Use the methods described in the ana::time namespace to create time lapses.
00601              *
00602              * Examples:
00603              *     - client->waiting_for_message( ana::time::seconds( 5 ) );
00604              *
00605              * @sa error_code
00606              */
00607             virtual void expecting_message( size_t ms_until_timeout ) = 0;
00608 
00609             // Allow server objects to invoke run_listener directly.
00610             using detail::listener::run_listener;
00611 
00612             /** Allow external object to call set_header_first_mode() directly. */
00613             using ana::detail::ana_component::set_header_first_mode;
00614 
00615             /** Allow external object to call set_raw_data_mode() directly. */
00616             using ana::detail::ana_component::set_raw_data_mode;
00617         };
00618     };
00619 
00620     /**
00621      * A network client.
00622      *
00623      * \sa listener
00624      * \sa sender
00625      */
00626     struct client : public virtual detail::listener,
00627                     public         detail::sender
00628     {
00629         /**
00630          * Creates a client.
00631          *
00632          * @param address : The network address of the server.
00633          * @param port : The network port of the server.
00634          */
00635         static client* create(address address, port port);
00636 
00637         /**
00638          * Attempt a connection to the server.
00639          *
00640          * @param handler : The handler of the connection event.
00641          *
00642          * @returns : The unique operation id of the connect operation.
00643          *
00644          * \sa connection_handler
00645          */
00646         virtual void connect( connection_handler* ) = 0;
00647 
00648         /**
00649          * Attempt a connection to the server through a proxy.
00650          *
00651          * @param handler : The handler of the connection event.
00652          *
00653          * @returns : The unique operation id of the connect operation.
00654          *
00655          * \sa connection_handler
00656          */
00657         virtual void connect_through_proxy(std::string         proxy_address,
00658                                            std::string         proxy_port,
00659                                            connection_handler* handler,
00660                                            std::string         user_name = "",
00661                                            std::string         password  = "") = 0;
00662 
00663         /**
00664          * Run the client listener, starts listening for incoming messages.
00665          *
00666          * Each time you call this method, a new thread will be started on the io_service object
00667          * from asio. This means that it is possible to have multiple threads running the service,
00668          * thus more threads will be able to run the handlers you implement.
00669          *
00670          * The drawback is, however, that if you run the service on multiple threads, then you must
00671          * be aware that the execution of your handlers may occur concurrently and thus you have to
00672          * prevent all of the troubles arising from this concurrency.
00673          *
00674          * Note that if you just call this method once, then you ensure mutual exclusion between
00675          * your handlers, just make sure you don't block waiting for a call to a handler from one
00676          * of your handlers, otherwise you'll always get a deadlock.
00677          */
00678         virtual void run() = 0;
00679 
00680         /**
00681          * Send a buffer or memory portion to the server.
00682          *
00683          * Examples:
00684          *    - client_->send( ana::buffer( str ), this );
00685          *    - client_->send( ana::buffer( large_pod_array ), handler_object, ana::ZERO_COPY );
00686          *
00687          * @param buffer : The buffer being sent.
00688          * @param handler : Handler of events resulting from this operation.
00689          * @param send_type : Optional, type of the send operation. Defaults to COPY_BUFFER.
00690          *
00691          * @returns : The unique operation id of the send operation.
00692          *
00693          * \sa send_type
00694          * \sa buffer
00695          * \sa send_handler
00696          */
00697         virtual operation_id send(boost::asio::const_buffer buffer,
00698                                   send_handler*             handler,
00699                                   send_type                 type = COPY_BUFFER ) = 0;
00700 
00701         /**
00702          * Cancel all pending network operations.
00703          *
00704          * Every pending operation handler will be invoked with ana::operation_aborted
00705          * as the corresponding error_code, except that the error code will be
00706          * boost::asio::error::operation_not_supported when run on Windows XP,
00707          * Windows Server 2003, and earlier versions of Windows,
00708          * unless BOOST_ASIO_ENABLE_CANCELIO is defined.
00709          */
00710         virtual void cancel_pending( )                             = 0;
00711 
00712         /**
00713          * Signal the client that you are waiting for a message from the server before a given time.
00714          *
00715          * The time parameter indicates how long you are willing to wait.
00716          *
00717          * If a message is received before this time period then this call will be insignificant.
00718          * However, if no such message is received, the appropriate call to handle_receive will be
00719          * made with ana::timeout_error as the error_code parameter.
00720          *
00721          * Use the methods described in the ana::time namespace to create time lapses.
00722          *
00723          * Examples:
00724          *     - client->waiting_for_message( ana::time::seconds( 5 ) );
00725          *
00726          * @sa error_code
00727          */
00728         virtual void expecting_message( size_t ms_until_timeout ) = 0;
00729 
00730         /**
00731          * Set a timeout value for connection attempts. If attempting to connect through a proxy
00732          * this value will be used once for the whole connection attempt.
00733          *
00734          * You should use the time lapse constructors in namespace ana::time:
00735          *      - ana::time::seconds(10)
00736          *      - ana::time::minutes(1)
00737          *
00738          * @sa ana::time
00739          */
00740         virtual void set_connect_timeout( size_t ms ) = 0;
00741 
00742         /** Returns the string representing the ip address of the connected client. */
00743         virtual std::string ip_address() const = 0;
00744 
00745         /** Standard destructor. */
00746         virtual ~client() {}
00747     };
00748     //@}
00749 }
00750 
00751 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Tue May 22 2012 01:03:39 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs