CppCMS
Public Member Functions
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

List of all members.

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)
std::string reactor_name ()

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)

Create io service using default reactor

Destroy io_service. It should be stopped before!.


Member Function Documentation

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

Cancel timer created with set_timer_event() asynchronously,

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.

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

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

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().

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.

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: