Ignore:
Timestamp:
06/27/11 13:00:22 (13 years ago)
Author:
tbretz
Message:
Added the possbility to give an IP Address with a port rather than a name which must be resolved; send keep alive packages in 10s intervals
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Connection.h

    r11118 r11190  
    44#include <deque>
    55#include <string>
     6#include <boost/bind.hpp>
    67#include <boost/asio.hpp>
    78#include <boost/function.hpp>
     
    1718    std::string fAddress;
    1819    std::string fPort;
     20
     21    boost::asio::ip::tcp::endpoint fEndpoint;
    1922
    2023    bool fDebugTx;
     
    4851    void AsyncRead(const boost::asio::mutable_buffers_1 buffers, int type=0);
    4952    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
    5071    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
    5277
    5378private:
    5479    void AsyncConnect(boost::asio::ip::tcp::resolver::iterator iterator);
     80    void AsyncConnect();
    5581
    5682    void CloseImp(bool restart=true);
    5783
    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);
    6088
    6189    void HandleConnectionTimer(const boost::system::error_code &error);
     
    75103    void SetEndpoint(const std::string &addr, const std::string &port);
    76104    void SetEndpoint(const std::string &addr);
     105    void SetEndpoint(const boost::asio::ip::tcp::endpoint &ep) { fEndpoint = ep; }
    77106
    78107    void StartConnect();
     
    112141
    113142    std::string URL() const { return fAddress + ":" + fPort; }
     143
     144    const boost::asio::ip::tcp::endpoint &GetEndpoint() const { return fEndpoint; }
    114145};
    115146
Note: See TracChangeset for help on using the changeset viewer.