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_CLIENT_HPP
00034 #define ASIO_CLIENT_HPP
00035
00036 #include <list>
00037
00038 #include <boost/asio.hpp>
00039 #include <memory>
00040
00041 using boost::asio::ip::tcp;
00042
00043 #include "../api/ana.hpp"
00044
00045 #include "asio_proxy_connection.hpp"
00046 #include "asio_listener.hpp"
00047 #include "asio_sender.hpp"
00048
00049
00050 class asio_client : public ana::client,
00051 public asio_listener,
00052 private proxy_connection_manager,
00053 private asio_sender
00054 {
00055 public:
00056
00057
00058
00059
00060
00061
00062 asio_client(std::string address, ana::port port);
00063
00064 virtual ~asio_client();
00065
00066 private:
00067
00068 virtual void connect( ana::connection_handler* );
00069
00070 virtual void connect_through_proxy(std::string proxy_address,
00071 std::string proxy_port,
00072 ana::connection_handler* handler,
00073 std::string user_name = "",
00074 std::string password = "");
00075
00076 virtual void run();
00077
00078 virtual ana::operation_id send( boost::asio::const_buffer,
00079 ana::send_handler*,
00080 ana::send_type );
00081
00082 virtual void disconnect() { disconnect_listener(); }
00083
00084 virtual void disconnect_listener();
00085
00086 virtual void handle_proxy_connection(const boost::system::error_code&,
00087 ana::connection_handler*,
00088 ana::timer*);
00089
00090 virtual tcp::socket& socket();
00091
00092 virtual void log_receive( ana::read_buffer buffer );
00093
00094 virtual const ana::stats* get_stats( ana::stat_type type ) const;
00095
00096 virtual ana::stats_collector& stats_collector();
00097
00098 virtual ana::timer* create_timer() { return new ana::timer( io_service_); }
00099
00100 virtual void cancel_pending( );
00101
00102 virtual void set_connect_timeout( size_t ms );
00103
00104 virtual void expecting_message( size_t ms_until_timeout );
00105
00106 virtual std::string ip_address() const;
00107
00108 void handle_connect(const boost::system::error_code& ec,
00109 tcp::resolver::iterator endpoint_iterator,
00110 ana::connection_handler*,
00111 ana::timer*);
00112
00113 void inform_connection_result( ana::connection_handler*, ana::error_code);
00114
00115 void handle_timeout(const boost::system::error_code& ec,
00116 ana::connection_handler*,
00117 ana::timer*);
00118
00119 ana::timer* start_connection_timer(ana::connection_handler*);
00120
00121
00122 asio_client(const asio_client& other);
00123 asio_client& operator= (const asio_client& other);
00124
00125
00126 boost::asio::io_service io_service_;
00127 std::list<boost::thread*> io_threads_;
00128 boost::asio::io_service::work work_;
00129
00130 tcp::socket socket_;
00131
00132 std::string address_;
00133 ana::port port_;
00134
00135 size_t connect_timeout_ms_;
00136
00137 proxy_connection* proxy_;
00138 bool use_proxy_;
00139
00140 ana::stats_collector stats_collector_;
00141 ana::operation_id last_valid_operation_id_;
00142
00143 boost::mutex connection_informed_mutex_;
00144 bool connection_informed_;
00145 };
00146
00147 #endif