1 #ifndef FACT_Connection 2 #define FACT_Connection 8 #include <boost/bind.hpp> 9 #include <boost/asio.hpp> 10 #include <boost/function.hpp> 11 #include <boost/asio/deadline_timer.hpp> 51 std::ostream &
Out() {
return fLog ? fLog->
Out() :
Out(); }
55 void AsyncRead(
const boost::asio::mutable_buffers_1 buffers,
int type=0);
56 void AsyncWrite(
const boost::asio::const_buffers_1 &buffers);
59 void AsyncWaitImp(boost::asio::deadline_timer &timer,
int millisec,
60 void (T::*
handler)(
const boost::system::error_code&))
70 timer.expires_from_now(boost::posix_time::milliseconds(millisec));
72 timer.async_wait(boost::bind(handler,
this, boost::asio::placeholders::error));
75 void AsyncWait(boost::asio::deadline_timer &timer,
int millisec,
76 void (
Connection::*handler)(
const boost::system::error_code&))
83 void AsyncConnect(boost::asio::ip::tcp::resolver::iterator iterator);
88 bool ConnectImp(
const boost::asio::ip::tcp::endpoint &endpoint,
89 const boost::system::error_code& error);
90 void ConnectIter(boost::asio::ip::tcp::resolver::iterator endpoint_iterator,
91 const boost::system::error_code& error);
92 void ConnectAddr(
const boost::asio::ip::tcp::endpoint &endpoint,
93 const boost::system::error_code& error);
97 void HandleSentData(
const boost::system::error_code& error,
size_t);
105 Connection(boost::asio::io_service& io_service, std::ostream &out);
109 void SetEndpoint(
const std::string &addr,
int port);
110 void SetEndpoint(
const std::string &addr,
const std::string &port);
112 void SetEndpoint(
const boost::asio::ip::tcp::endpoint &ep);
121 void PostMessage(
const std::string &cmd,
size_t s=-1);
123 template<
typename T,
size_t N>
151 std::string
URL()
const {
return fAddress +
":" +
fPort; }
void PostMessage(const void *msg, size_t s=0)
void SetDebugTx(bool b=true)
boost::asio::deadline_timer fConnectionTimer
bool ConnectImp(const boost::asio::ip::tcp::endpoint &endpoint, const boost::system::error_code &error)
void AsyncWait(boost::asio::deadline_timer &timer, int millisec, void(Connection::*handler)(const boost::system::error_code &))
boost::asio::deadline_timer fInTimeout
void PostClose(bool restart=true)
virtual void HandleReceivedData(const boost::system::error_code &, size_t, int=0)
bool IsDisconnected() const
void HandleConnectionTimer(const boost::system::error_code &error)
The base implementation of a distributed messaging system.
Adds some functionality to boost::posix_time::ptime for our needs.
void CloseImp(bool restart=true)
int Write(const Time &t, const std::string &txt, int qos=kInfo)
void HandleWriteTimeout(const boost::system::error_code &error)
void HandleSentData(const boost::system::error_code &error, size_t)
bool IsConnecting() const
void SetEndpoint(const std::string &addr, int port)
std::ostream & Out() const
ConnectionStatus_t fConnectionStatus
virtual void ConnectionFailed()
void AsyncWaitImp(boost::asio::deadline_timer &timer, int millisec, void(T::*handler)(const boost::system::error_code &))
An info telling something which can be interesting to know.
virtual void StartConnect()
void AsyncWrite(const boost::asio::const_buffers_1 &buffers)
boost::asio::ip::tcp::endpoint fEndpoint
void ConnectAddr(const boost::asio::ip::tcp::endpoint &endpoint, const boost::system::error_code &error)
void SetLogStream(MessageImp *log)
void SetVerbose(bool b=true)
void AsyncRead(const boost::asio::mutable_buffers_1 buffers, int type=0)
void ConnectIter(boost::asio::ip::tcp::resolver::iterator endpoint_iterator, const boost::system::error_code &error)
virtual void HandleReadTimeout(const boost::system::error_code &)
const boost::asio::ip::tcp::endpoint & GetEndpoint() const
bool IsTxQueueEmpty() const
static void handler(int conn_id, char *packet, int size, int status)
void PostMessage(const std::array< T, N > &msg)
Connection(boost::asio::io_service &io_service, std::ostream &out)
void PostMessage(const std::vector< T > &msg)
virtual void ConnectionEstablished()
boost::asio::deadline_timer fOutTimeout
Maintains an ansynchronous TCP/IP client connection.