reactor.qbk 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. [/
  2. / Copyright (c) 2003-2019 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. [section:reactor Reactor-Style Operations]
  8. Sometimes a program must be integrated with a third-party library that wants to
  9. perform the I/O operations itself. To facilitate this, Boost.Asio includes
  10. synchronous and asynchronous operations that may be used to wait for a socket
  11. to become ready to read, ready to write, or to have a pending error condition.
  12. As an example, to perform a non-blocking read something like the following may
  13. be used:
  14. ip::tcp::socket socket(my_io_context);
  15. ...
  16. socket.non_blocking(true);
  17. ...
  18. socket.async_wait(ip::tcp::socket::wait_read, read_handler);
  19. ...
  20. void read_handler(boost::system::error_code ec)
  21. {
  22. if (!ec)
  23. {
  24. std::vector<char> buf(socket.available());
  25. socket.read_some(buffer(buf));
  26. }
  27. }
  28. These operations are supported for sockets on all platforms, and for the POSIX
  29. stream-oriented descriptor classes.
  30. [heading See Also]
  31. [link boost_asio.reference.basic_socket.wait basic_socket::wait()],
  32. [link boost_asio.reference.basic_socket.async_wait basic_socket::async_wait()],
  33. [link boost_asio.reference.basic_socket.non_blocking basic_socket::non_blocking()],
  34. [link boost_asio.reference.basic_socket.native_non_blocking basic_socket::native_non_blocking()],
  35. [link boost_asio.examples.cpp03_examples.nonblocking nonblocking example].
  36. [endsect]