1[/
2 / Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
3 /
4 / Distributed under the Boost Software License, Version 1.0. (See accompanying
5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 /]
7
8[section:reactor Reactor-Style Operations]
9
10Sometimes a program must be integrated with a third-party library that wants to
11perform the I/O operations itself. To facilitate this, Boost.Asio includes
12synchronous and asynchronous operations that may be used to wait for a socket
13to become ready to read, ready to write, or to have a pending error condition.
14
15As an example, to perform a non-blocking read something like the following may
16be used:
17
18  ip::tcp::socket socket(my_io_context);
19  ...
20  socket.non_blocking(true);
21  ...
22  socket.async_wait(ip::tcp::socket::wait_read, read_handler);
23  ...
24  void read_handler(boost::system::error_code ec)
25  {
26    if (!ec)
27    {
28      std::vector<char> buf(socket.available());
29      socket.read_some(buffer(buf));
30    }
31  }
32
33These operations are supported for sockets on all platforms, and for the POSIX
34stream-oriented descriptor classes.
35
36[heading See Also]
37
38[link boost_asio.reference.basic_socket.wait basic_socket::wait()],
39[link boost_asio.reference.basic_socket.async_wait basic_socket::async_wait()],
40[link boost_asio.reference.basic_socket.non_blocking basic_socket::non_blocking()],
41[link boost_asio.reference.basic_socket.native_non_blocking basic_socket::native_non_blocking()],
42[link boost_asio.examples.cpp03_examples.nonblocking nonblocking example].
43
44[endsect]
45