Public Member Functions | List of all members
booster::aio::io_service Class Reference

this is the central event loop that dispatches all requests. More...

#include <booster/booster/aio/io_service.h>

Inheritance diagram for booster::aio::io_service:
booster::noncopyable booster::aio::io_events

Public Member Functions

 io_service (int reactor_type)
 io_service ()
 ~io_service ()
void set_io_event (native_type fd, int event, event_handler const &h)
void cancel_io_events (native_type fd)
int set_timer_event (ptime const &point, event_handler const &h)
void cancel_timer_event (int event_id)
void run ()
void run (system::error_code &e)
void reset ()
void stop ()
void post (handler const &h)
void post (event_handler const &h, booster::system::error_code const &e)
void post (io_handler const &h, booster::system::error_code const &e, size_t n)
std::string reactor_name ()

Additional Inherited Members

- Static Public Attributes inherited from booster::aio::io_events
static const int in = 1 << 0
static const int out = 1 << 1
static const int err = 1 << 2

Detailed Description

this is the central event loop that dispatches all requests.

This all this class member functions are thread safe unless specified otherwise.

However only single thread may execute run() member function and dispatch its handlers, this class also can be safely created before fork and used after it

Constructor & Destructor Documentation

booster::aio::io_service::io_service ( int  reactor_type)

Create io service using specific reactor type and not default one (see reactor's class use_* constants)

booster::aio::io_service::io_service ( )

Create io service using default reactor

booster::aio::io_service::~io_service ( )

Destroy io_service. It should be stopped before!.

Member Function Documentation

void booster::aio::io_service::cancel_io_events ( native_type  fd)

Cancel all io-events for file descriptor fd. Event handlers associated with this descriptor are dispatched asynchronously with aio_error::canceled error code.

void booster::aio::io_service::cancel_timer_event ( int  event_id)

Cancel timer created with set_timer_event() asynchronously,

void booster::aio::io_service::post ( handler const &  h)

Post a single handler h for immediate execution in the event loop queue. Useful for execution of some job in the thread that runs the event loop of the io_service.

void booster::aio::io_service::post ( event_handler const &  h,
booster::system::error_code const &  e 

Post event completion hander with its status

New in CppCMS 1.2

void booster::aio::io_service::post ( io_handler const &  h,
booster::system::error_code const &  e,
size_t  n 

Post event i/o completion hander with its status and i/o size

New in CppCMS 1.2

std::string booster::aio::io_service::reactor_name ( )

Get the real name of the reactor that io_service uses (calls reactor::name())

void booster::aio::io_service::reset ( )

Prepare the service after it was stopped. This function is not thread safe.

void booster::aio::io_service::run ( )

Run main event loop. This function starts actual event loop. It does not return until stop is called or error occurs.

If error occurs (exception is thrown) you may try to restart the event loop by calling run once again.

However if run() is exited normally (i.e. by calling stop()) then you need to call reset() member function before next call of run().

void booster::aio::io_service::run ( system::error_code e)

Same as run(), but, event-loop specific errors are reported via e error code rather then by throwing. Note, event handlers still may throw.

void booster::aio::io_service::set_io_event ( native_type  fd,
int  event,
event_handler const &  h 

Set event handler h for file descriptor fd. event can be io_events::in, io_events::out or io_events::in | io_events::out.

Error handling:

  • If invalid event type is given, std::invalid_argument is throw.
  • All other applicative errors are always reported using event handler h and never thrown directly.
int booster::aio::io_service::set_timer_event ( ptime const &  point,
event_handler const &  h 

Create a timer that expires in point time, that is handled with h handler. the handler will be called only in two cases:

  • When the current time >= point.
  • Timer was canceled. h will be dispatched with aio_error::canceled error code.

The return value is special identification for the specific timer, it can be used for timer cancellation. Once cancel_timer_event is called with this unique identification, it should never be called again with this id as other timer may receive this identification.

void booster::aio::io_service::stop ( )

Stop the service. All threads executing run() function will exit from it. You can't use this service till you call reset() function.

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