]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/ |
2 | / Copyright (c) 2003-2016 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 | ||
10 | Sometimes a program must be integrated with a third-party library that wants to | |
11 | perform the I/O operations itself. To facilitate this, Boost.Asio includes a | |
12 | `null_buffers` type that can be used with both read and write operations. A | |
13 | `null_buffers` operation doesn't return until the I/O object is "ready" to | |
14 | perform the operation. | |
15 | ||
16 | As an example, to perform a non-blocking read something like the | |
17 | following may be used: | |
18 | ||
19 | ip::tcp::socket socket(my_io_service); | |
20 | ... | |
21 | socket.non_blocking(true); | |
22 | ... | |
23 | socket.async_read_some(null_buffers(), read_handler); | |
24 | ... | |
25 | void read_handler(boost::system::error_code ec) | |
26 | { | |
27 | if (!ec) | |
28 | { | |
29 | std::vector<char> buf(socket.available()); | |
30 | socket.read_some(buffer(buf)); | |
31 | } | |
32 | } | |
33 | ||
34 | These operations are supported for sockets on all platforms, and for the POSIX | |
35 | stream-oriented descriptor classes. | |
36 | ||
37 | [heading See Also] | |
38 | ||
39 | [link boost_asio.reference.null_buffers null_buffers], | |
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] |