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_transport Class Reference

#include <thrift_asio_transport.hpp>

Inheritance diagram for betabugs::networking::thrift_asio_transport:
betabugs::networking::thrift_asio_client_transport

Classes

struct  event_handlers
 

Public Types

typedef std::shared_ptr
< boost::asio::ip::tcp::socket > 
socket_ptr
 a shared_ptr to a tcp socket
 

Public Member Functions

 thrift_asio_transport (socket_ptr socket, event_handlers *event_handlers)
 creates a thrift_asio_transport from a socket_ptr
 
uint32_t read (uint8_t *buf, uint32_t len)
 Attempt to read up to the specified number of bytes into the string. More...
 
size_t available_bytes () const
 the number of bytes, that have been received on not yet read()
 
void write (const uint8_t *buf, uint32_t len)
 
virtual bool isOpen () override
 return true unless an error occured or the transport was closed
 
bool isClosed ()
 Checks wether this transport is closed. More...
 
virtual bool peek () override
 return true, if there is data available to be processed
 
virtual void open () override
 opens the transport
 
virtual void close () override
 closes the transport
 
virtual const std::string getOrigin () override
 

Protected Types

enum  State { CLOSED, CONNECTING, RESOLVING, OPEN }
 enum to represent the state-machine of the connection More...
 

Protected Attributes

State state_ = CLOSED
 the state of this transport
 
socket_ptr socket_
 the underlying socket
 
event_handlersevent_handlers_
 handles events like on_error, etc.
 

Detailed Description

thrift transport that employs a boost::asio::socket.

If you want name resolution, it might be easier to use thrift_asio_client_transport

Member Enumeration Documentation

enum to represent the state-machine of the connection

Enumerator
CLOSED 

the transport is closed

CONNECTING 

the transport is currently connecting

RESOLVING 

we're currently trying to resolve host_name:service_name

OPEN 

the transport is open and ready for communication

Member Function Documentation

virtual const std::string betabugs::networking::thrift_asio_transport::getOrigin ( )
inlineoverridevirtual

Returns the origin of the transports call. The value depends on the transport used. An IP based transport for example will return the IP address of the client making the request. If the transport doesn't know the origin Unknown is returned.

The returned value can be used in a log message for example

bool betabugs::networking::thrift_asio_transport::isClosed ( )
inline

Checks wether this transport is closed.

Returns
true, if the transport is closed, false if the connection is open or name resolution is in progress.
uint32_t betabugs::networking::thrift_asio_transport::read ( uint8_t *  buf,
uint32_t  len 
)
inline

Attempt to read up to the specified number of bytes into the string.

This does not block if data is available. But it does block, if there is not enough data. If you don't want to block, use available_bytes() to check if there's enough data.

Parameters
bufReference to the location to write the data
lenHow many bytes to read
Returns
How many bytes were actually read
void betabugs::networking::thrift_asio_transport::write ( const uint8_t *  buf,
uint32_t  len 
)
inline

asynchronously sends len bytes from buf.

In case of error, the event_handler::on_error will be invoked.

Parameters
bufThe data to write out
lennumber of bytes to read from buf

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