Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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