5 #ifndef _THRIFT_ASIO_CLIENT_HPP_
6 #define _THRIFT_ASIO_CLIENT_HPP_
10 #include <boost/smart_ptr/enable_shared_from_raw.hpp>
11 #include "./thrift_asio_client_transport.hpp"
12 #include <thrift/protocol/TBinaryProtocol.h>
13 #include <thrift/transport/TBufferTransports.h>
16 namespace networking {
28 typename ProcessorType,
29 typename HandlerInterfaceType
32 :
public HandlerInterfaceType
33 ,
public boost::enable_shared_from_raw
34 ,
public thrift_asio_client_transport::event_handlers
39 boost::asio::io_service& io_service,
40 const std::string& host_name,
41 const std::string& service_name
43 : io_service_(io_service)
44 , processor_(boost::shared_from_raw(this))
46 io_service, host_name, service_name, this
50 boost::make_shared<apache::thrift::protocol::TBinaryProtocol>(
51 boost::make_shared<apache::thrift::transport::TFramedTransport>(
58 protocol_->getTransport()->open();
64 while (transport_->isOpen() && transport_->peek())
66 processor_.process(protocol_,
nullptr,
nullptr);
71 void connect_to(
const std::string& host_name,
const std::string service_name)
73 transport_->connect_to(host_name, service_name);
77 void reconnect_in(
const boost::posix_time::time_duration& duration)
79 auto timer = std::make_shared<boost::asio::deadline_timer>(io_service_);
80 timer->expires_from_now(duration);
82 [timer,
this](
const boost::system::error_code& ec)
85 else transport_->open();
91 boost::asio::io_service& io_service_;
92 ProcessorType processor_;
94 boost::shared_ptr<thrift_asio_client_transport> transport_;
95 boost::shared_ptr<apache::thrift::protocol::TProtocol> protocol_;
107 #endif //_THRIFT_ASIO_CLIENT_HPP_
void update()
process incoming traffic
Definition: thrift_asio_client.hpp:62
thrift_asio_client(boost::asio::io_service &io_service, const std::string &host_name, const std::string &service_name)
creates a thrift_asio_client and tries to connect to host_name:service_name
Definition: thrift_asio_client.hpp:38
void reconnect_in(const boost::posix_time::time_duration &duration)
reconnect in seconds seconds
Definition: thrift_asio_client.hpp:77
An asynchronous bidirectional thrift client.
Definition: thrift_asio_client.hpp:31
void connect_to(const std::string &host_name, const std::string service_name)
close the connection and connect to host_name:service_name
Definition: thrift_asio_client.hpp:71
ClientType client_
the client used to communicate with the server
Definition: thrift_asio_client.hpp:97
Definition: thrift_asio_client_transport.hpp:20