View on GitHub

Thrift Asio

Asynchronous client and server for apache thrift implemented via boost::asio

Download this project as a .zip file Download this project as a tar.gz file
betabugs::networking::thrift_asio_server< HandlerType > Class Template Reference

#include <thrift_asio_server.hpp>

Static Public Member Functions

static void serve (boost::asio::io_service &io_service, TProcessor &processor, Handler_ptr handler, unsigned short port)
 

Detailed Description

template<typename HandlerType>
class betabugs::networking::thrift_asio_server< HandlerType >

Use this class on the server

Template Parameters
HandlerTypethe type of the implementation of a handler.

HandlerType

First of all the HandlerType must work with the auto-generated processor you're using. it must also be inherited from thrift_asio_transport::event_handlers to be able to receive transport errors. lastly it must implement the following member functions:

void on_client_connected(boost::shared_ptr<apache::thrift::protocol::TProtocol> output_protocol);
void on_client_disconnected(const boost::shared_ptr<apache::thrift::protocol::TProtocol>& output_protocol, const boost::system::error_code& ec);
void before_process(boost::shared_ptr<apache::thrift::protocol::TProtocol> output_protocol);
void after_process();

or you can simply inherit your server side handler from thrift_asio_connection_management_mixin

Examples:
example_server.cpp.

Member Function Documentation

template<typename HandlerType>
static void betabugs::networking::thrift_asio_server< HandlerType >::serve ( boost::asio::io_service &  io_service,
TProcessor &  processor,
Handler_ptr  handler,
unsigned short  port 
)
inlinestatic

call this to start listening for incoming connections. This call is non blocking. To actually service the clients, make sure, that you run/poll the io_service, i.e.

// in a "realtime" context (game/audio-processor/etc.)
void call_me_once_per_frame()
{
// drain outstanding handlers
while (io_service.poll_one());
}

The nice thing about this is, that you RCP-calls will be made from the thread that is calling call_me_once_per_frame(). This means, you'll need no (or a lot less) locking. This is much more suitable for a "realtime" environment.


The documentation for this class was generated from the following file: