ana/src/asio_listener.hpp

Go to the documentation of this file.
00001 /* $Id: asio_listener.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 
00003 /**
00004  * @file
00005  * @brief Header file of a listener for the ana project.
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  * System:         ana
00013  * Language:       C++
00014  *
00015  * Author:         Guillermo Biset
00016  * E-Mail:         billybiset AT gmail DOT com
00017  *
00018  * ana is free software: you can redistribute it and/or modify
00019  * it under the terms of the GNU General Public License as published by
00020  * the Free Software Foundation, either version 2 of the License, or
00021  * (at your option) any later version.
00022  *
00023  * ana is distributed in the hope that it will be useful,
00024  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00025  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00026  * GNU General Public License for more details.
00027  *
00028  * You should have received a copy of the GNU General Public License
00029  * along with ana.  If not, see <http://www.gnu.org/licenses/>.
00030  *
00031  */
00032 
00033 #ifndef ASIO_LISTENER_HPP
00034 #define ASIO_LISTENER_HPP
00035 
00036 #include <boost/asio.hpp>
00037 #include <memory>
00038 
00039 #include "../api/ana.hpp"
00040 
00041 using boost::asio::ip::tcp;
00042 
00043 class asio_listener : public virtual ana::detail::listener
00044 {
00045     public:
00046         asio_listener( );
00047 
00048         virtual void set_listener_handler( ana::listener_handler* listener);
00049         virtual void run_listener();
00050 
00051         virtual ~asio_listener();
00052 
00053     protected:
00054         virtual tcp::socket& socket() = 0;
00055 
00056         void wait_for_incoming_message( size_t ms_to_timeout, ana::net_id id = 0  );
00057 
00058     private:
00059         virtual void disconnect_listener()                   {}
00060 
00061         virtual void set_raw_buffer_max_size( size_t size );
00062 
00063         virtual void wait_raw_object(ana::serializer::bistream& bis, size_t size);
00064 
00065         void listen_one_message();
00066 
00067         void disconnect( boost::system::error_code error);
00068 
00069         void handle_header(char* header, const boost::system::error_code& );
00070 
00071         void handle_body( ana::read_buffer , const boost::system::error_code& );
00072 
00073         void handle_partial_body( ana::read_buffer,
00074                                   const boost::system::error_code&,
00075                                   size_t accumulated,
00076                                   size_t last_msg_size);
00077 
00078         void handle_timeout( const boost::system::error_code&, ana::net_id);
00079 
00080         void handle_raw_buffer( ana::read_buffer, const boost::system::error_code&, size_t);
00081 
00082         /*attr*/
00083         bool                       disconnected_;
00084         ana::listener_handler*     listener_;
00085         char                       header_[ana::HEADER_LENGTH];
00086         size_t                     raw_mode_buffer_size_;
00087 
00088         ana::timer*                next_message_timer_;
00089 };
00090 
00091 #endif
00092 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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