This article relies on a single source. (April 2024) |
| Asio C++ library | |
|---|---|
| Original author | Christopher M. Kohlhoff |
| Stable release | 1.38.2
/ July 19, 2026 |
| Written in | C++ |
| Type | Library or framework |
| License | Boost Software License |
| Website | think-async |
| Repository | |
Asio (asio) is a freely available, open-source, cross-platform C++ library for network programming. It provides developers with a asynchronous I/O model. The library has been developed by Christopher M. Kohlhoff since 2003.
Boost.Asio (boost::asio) was accepted into Boost on 30 December 2005 after a 20-day review.
As of 2024, Asio continues to evolve, with ongoing contributions from the community and enhancements to its functionality. The library is regularly updated to support the latest C++ standards and best practices in network programming. Developers are encouraged to explore the extensive documentation and tutorials available on the official Asio website, which cover a wide range of topics, from basic usage to advanced features. Boost.Asio also supports working with C++20 coroutines.
The API below is expressed in terms of the original asio library, whose namespace is asio; its Boost counterpart instead uses the boost::asio namespace.
asio::io_context: the context for asynchronous I/O, which monitors asynchronous tasks and maintains a queue of completed operations ready to execute. Acts as an interface to the operating system's multiplexing mechanism.asio::executor: a lightweight handle or strategy determining where and how a function a function/completion handler should run.asio::steady_timer, asio::system_timer: time-management objects used to delay execution or enforce timeouts on operationsasio::posix::stream_descriptor, asio::windows::stream_handle: OS-specific abstractions for native files/pipes/console streamsasio::ip::icmp: the flags and types needed for Internet Control Message Protocol (ICMP).
asio::ip::tcp: the flags and types needed for Transmission Control Protocol (TCP).
asio::ip::tcp::acceptor: the TCP acceptor typeasio::ip::tcp::endpoint: the TCP endpoint typeasio::ip::tcp::iostream: the TCP iostream typeasio::ip::tcp::resolver: the TCP resolver typeasio::ip::tcp::socket: the TCP socket typeasio::ip::udp: the flags and types needed for User Datagram Protocol (UDP).
asio::ip::udp::endpoint: the UDP endpoint typeasio::ip::udp::resolver: the UDP resolver typeasio::ip::udp::socket: the UDP socket typeUsed to point to memory blocks without copying data, for wrapping over arrays and sequential containers, akin to std::span<T> and std::string_view.
asio::const_buffer: a read-only view of a memory block (for writing data out to a socket)asio::mutable_buffer: a writable view of a memory block (for reading incoming data in from a socket)asio::streambuf: a dynamically-resizing stream-style buffer (extends std::streambuf).asio::strand: a logical executor adapter for handler execution serialization; if an asio::io_context runs across a pool of multiple threads, handlers assigned to the same asio::strand are guaranteed to execute sequentially.Completion tokens are used to specify how to receive the result of an asynchronous operation, and are passed as the last argument of any function prefixed with "async". Traditionally, this is done with callbacks/lambdas.
asio::use_future: transforms the asynchronous function to return a std::future<T>.asio::use_awaitable: converts the asynchronous signature into a coroutine frame, allowing the use of co_await.The C++ Networking TS was itself based on asio, proposing asynchronous I/O and networking into the C++ standard library. It was implemented by some vendors, such as GCC.
The following headers were defined in the C++ networking TS. The symbols were placed in std::extensions::net (eventually for std::net).
| Name | Description |
|---|---|
<netfwd> |
Contains forward declarations of Networking TS components. |
<executor> |
Provides asynchronous models for networking. |
<io_context> |
Provides basic I/O services for networking. |
<timer> |
Provides timer operations for networking. |
<buffer> |
Provides buffers and buffer-oriented streams for networking. |
<socket> |
Provides sockets and socket streams for networking. |
<internet> |
Provides internet protocols for networking. |
<net> |
Includes all Networking TS headers. |
The networking API based on asio was first submitted to the C++ standards committee in 2006 for possible inclusion in the second Technical Report on C++ Library Extensions (TR2), however was not integrated, with the most recent development in 2020. Instead, in C++26, the std::execution framework (based on NVIDIA's stdexec library) was adopted into the C++ standard library as C++'s asynchronous programming framework, with an alternative asynchronous I/O API based on the Senders/Receiver model.