Changeset 11190 for trunk/FACT++/src/Connection.h
- Timestamp:
- 06/27/11 13:00:22 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Connection.h
r11118 r11190 4 4 #include <deque> 5 5 #include <string> 6 #include <boost/bind.hpp> 6 7 #include <boost/asio.hpp> 7 8 #include <boost/function.hpp> … … 17 18 std::string fAddress; 18 19 std::string fPort; 20 21 boost::asio::ip::tcp::endpoint fEndpoint; 19 22 20 23 bool fDebugTx; … … 48 51 void AsyncRead(const boost::asio::mutable_buffers_1 buffers, int type=0); 49 52 void AsyncWrite(const boost::asio::const_buffers_1 &buffers); 53 54 template<class T> 55 void AsyncWaitImp(boost::asio::deadline_timer &timer, int millisec, 56 void (T::*handler)(const boost::system::error_code&)) 57 { 58 // - The boost::asio::basic_deadline_timer::expires_from_now() 59 // function cancels any pending asynchronous waits, and returns 60 // the number of asynchronous waits that were cancelled. If it 61 // returns 0 then you were too late and the wait handler has 62 // already been executed, or will soon be executed. If it 63 // returns 1 then the wait handler was successfully cancelled. 64 // - If a wait handler is cancelled, the bs::error_code passed to 65 // it contains the value bs::error::operation_aborted. 66 timer.expires_from_now(boost::posix_time::milliseconds(millisec)); 67 68 timer.async_wait(boost::bind(handler, this, boost::asio::placeholders::error)); 69 } 70 50 71 void AsyncWait(boost::asio::deadline_timer &timer, int millisec, 51 void (Connection::*handler)(const boost::system::error_code&)); 72 void (Connection::*handler)(const boost::system::error_code&)) 73 { 74 AsyncWaitImp(timer, millisec, handler); 75 } 76 52 77 53 78 private: 54 79 void AsyncConnect(boost::asio::ip::tcp::resolver::iterator iterator); 80 void AsyncConnect(); 55 81 56 82 void CloseImp(bool restart=true); 57 83 58 void ConnectImp(const boost::system::error_code& error, 59 boost::asio::ip::tcp::resolver::iterator endpoint_iterator); 84 void ConnectAddrImp(const boost::asio::ip::tcp::endpoint &endpoint, 85 const boost::system::error_code& error); 86 void ConnectIterImp(boost::asio::ip::tcp::resolver::iterator endpoint_iterator, 87 const boost::system::error_code& error); 60 88 61 89 void HandleConnectionTimer(const boost::system::error_code &error); … … 75 103 void SetEndpoint(const std::string &addr, const std::string &port); 76 104 void SetEndpoint(const std::string &addr); 105 void SetEndpoint(const boost::asio::ip::tcp::endpoint &ep) { fEndpoint = ep; } 77 106 78 107 void StartConnect(); … … 112 141 113 142 std::string URL() const { return fAddress + ":" + fPort; } 143 144 const boost::asio::ip::tcp::endpoint &GetEndpoint() const { return fEndpoint; } 114 145 }; 115 146
Note:
See TracChangeset
for help on using the changeset viewer.