O'Reilly logo

Boost.Asio C++ Network Programming by John Torjo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The io_service class

You've already seen that most code that uses Boost.Asio will use some instance of io_service. The io_service is the most important class in the library; it deals with the operating system, waiting for all asynchronous operations to end, and then calling the completion handler for each such operation.

If you choose to create your application synchronously, you won't need to worry about what I'm about to show you in this section.

You can use io_service instances in several ways. In the following examples, we have three asynchronous operations, two socket connections and a timer wait:

  • Single-thread with one io_service and one handler thread:
    io_service service_; // all the socket operations are handled by service_ ip::tcp::socket ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required