What is Boost.Asio?
Boost.Asio is a cross-platform C++ library created by Chris Kohlhoff that provides a portable network and low-level I/O programming, including sockets, timers, hostname resolution, socket iostreams, serial ports, file descriptors, and Windows HANDLEs, providing a consistent asynchronous model. It also provides coroutine support, but as we learned in the previous chapter, they are now available in C++20, so we will only introduce them briefly in this chapter.
Boost.Asio allows the program to manage long-running operations without the explicit usage of threads and locks. Also, as it implements a layer on top of the OS services, it allows portability, efficiency, ease of use, and scalability, using the most appropriate underlying OS mechanisms to achieve these goals, for example, scatter-gather I/O operations or moving data across while minimizing costly copies.
Let’s start by learning about the basic Boost.Asio blocks, I/O objects, and I/O execution context...