...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Provides core I/O functionality.
class io_service : noncopyable
Name |
Description |
---|---|
Class used to uniquely identify a service. |
|
Base class for all io_service services. |
|
Provides serialised handler execution. |
|
Class to inform the io_service when it has work to do. |
Name |
Description |
---|---|
Request the io_service to invoke the given handler. |
|
Constructor. |
|
Run the io_service's event processing loop to execute ready handlers. |
|
Run the io_service's event processing loop to execute one ready handler. |
|
Request the io_service to invoke the given handler and return immediately. |
|
Reset the io_service in preparation for a subsequent run() invocation. |
|
Run the io_service's event processing loop. |
|
Run the io_service's event processing loop to execute at most one handler. |
|
Stop the io_service's event processing loop. |
|
Create a new handler that automatically dispatches the wrapped handler on the io_service. |
|
Destructor. |
Name |
Description |
---|---|
Add a service object to the io_service. |
|
Determine if an io_service contains a specified service type. |
|
Obtain the service object corresponding to the given type. |
The io_service class provides the core I/O functionality for users of the asynchronous I/O objects, including:
The io_service class also includes facilities intended for developers of custom asynchronous services.
Distinct objects: Safe.
Shared objects: Safe, with the exception that calling reset() while there are unfinished run() calls results in undefined behaviour.
If an exception is thrown from a handler, the exception is allowed to propagate through the throwing thread's invocation of boost::asio::io_service::run(), boost::asio::io_service::run_one(), boost::asio::io_service::poll() or boost::asio::io_service::poll_one(). No other threads that are calling any of these functions are affected. It is then the responsibility of the application to catch the exception.
After the exception has been caught, the boost::asio::io_service::run(), boost::asio::io_service::run_one(), boost::asio::io_service::poll() or boost::asio::io_service::poll_one() call may be restarted without the need for an intervening call to boost::asio::io_service::reset(). This allows the thread to rejoin the io_service's thread pool without impacting any other threads in the pool.
For example:
boost::asio::io_service io_service; ... for (;;) { try { io_service.run(); break; // run() exited normally } catch (my_exception& e) { // Deal with exception as appropriate. } }