A concurrent server using Boost.Asio
This section will demonstrate how to write concurrent programs that have multiple threads of execution but only use a single OS thread. We are about to implement a rudimentary concurrent single-threaded TCP server that can handle multiple clients. There are no networking capabilities in the C++ standard library, but fortunately Boost.Asio provides us with a platform-agnostic interface for handling socket communication.
Instead of wrapping the callback-based Boost.Asio API, I will demonstrate how to use the boost::asio::awaitable
class for the purpose of showing a more realistic example of how asynchronous application programming using coroutines can look. The class template boost::asio::awaitable
corresponds to the Task
template we created earlier; it's used as a return type for coroutines that represent asynchronous computations.
Implementing the server
The server is very simple; once a client connects, it starts updating a numeric...