3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>async_compose</title>
5 <link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../boost_asio.html" title="Boost.Asio">
8 <link rel="up" href="../reference.html" title="Reference">
9 <link rel="prev" href="async_completion/result.html" title="async_completion::result">
10 <link rel="next" href="async_connect.html" title="async_connect">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
15 <td align="center"><a href="../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="async_completion/result.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="async_connect.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="boost_asio.reference.async_compose"></a><a class="link" href="async_compose.html" title="async_compose">async_compose</a>
28 </h3></div></div></div>
30 <a class="indexterm" name="boost_asio.indexterm.async_compose"></a>
31 Launch an asynchronous operation
32 with a stateful implementation.
34 <pre class="programlisting">template<
35 typename CompletionToken,
37 typename Implementation,
38 typename... IoObjectsOrExecutors>
39 <a class="link" href="asynchronous_operations.html#boost_asio.reference.asynchronous_operations.automatic_deduction_of_initiating_function_return_type"><span class="emphasis"><em>DEDUCED</em></span></a> async_compose(
40 Implementation && implementation,
41 CompletionToken & token,
42 IoObjectsOrExecutors &&... io_objects_or_executors);
45 The async_compose function simplifies the implementation of composed asynchronous
46 operations automatically wrapping a stateful function object with a conforming
47 intermediate completion handler.
50 <a name="boost_asio.reference.async_compose.h0"></a>
51 <span class="phrase"><a name="boost_asio.reference.async_compose.parameters"></a></span><a class="link" href="async_compose.html#boost_asio.reference.async_compose.parameters">Parameters</a>
53 <div class="variablelist">
54 <p class="title"><b></b></p>
55 <dl class="variablelist">
56 <dt><span class="term">implementation</span></dt>
58 A function object that contains the implementation of the composed
59 asynchronous operation. The first argument to the function object is
60 a non-const reference to the enclosing intermediate completion handler.
61 The remaining arguments are any arguments that originate from the completion
62 handlers of any asynchronous operations performed by the implementation.
64 <dt><span class="term">token</span></dt>
68 <dt><span class="term">io_objects_or_executors</span></dt>
70 Zero or more I/O objects or I/O executors for which outstanding work
76 <a name="boost_asio.reference.async_compose.h1"></a>
77 <span class="phrase"><a name="boost_asio.reference.async_compose.example_"></a></span><a class="link" href="async_compose.html#boost_asio.reference.async_compose.example_">Example:</a>
79 <pre class="programlisting">struct async_echo_implementation
81 tcp::socket& socket_;
82 boost::asio::mutable_buffer buffer_;
83 enum { starting, reading, writing } state_;
85 template <typename Self>
86 void operator()(Self& self,
87 boost::system::error_code error = {},
94 socket_.async_read_some(
95 buffer_, std::move(self));
100 self.complete(error, 0);
105 boost::asio::async_write(socket_, buffer_,
106 boost::asio::transfer_exactly(n),
111 self.complete(error, n);
117 template <typename CompletionToken>
118 auto async_echo(tcp::socket& socket,
119 boost::asio::mutable_buffer buffer,
120 CompletionToken&& token) ->
121 typename boost::asio::async_result<
122 typename std::decay<CompletionToken>::type,
123 void(boost::system::error_code, std::size_t)>::return_type
125 return boost::asio::async_compose<CompletionToken,
126 void(boost::system::error_code, std::size_t)>(
127 async_echo_implementation{socket, buffer,
128 async_echo_implementation::starting},
133 <a name="boost_asio.reference.async_compose.h2"></a>
134 <span class="phrase"><a name="boost_asio.reference.async_compose.requirements"></a></span><a class="link" href="async_compose.html#boost_asio.reference.async_compose.requirements">Requirements</a>
137 <span class="emphasis"><em>Header: </em></span><code class="literal">boost/asio/compose.hpp</code>
140 <span class="emphasis"><em>Convenience header: </em></span><code class="literal">boost/asio.hpp</code>
143 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
144 <td align="left"></td>
145 <td align="right"><div class="copyright-footer">Copyright © 2003-2019 Christopher M. Kohlhoff<p>
146 Distributed under the Boost Software License, Version 1.0. (See accompanying
147 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
152 <div class="spirit-nav">
153 <a accesskey="p" href="async_completion/result.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="async_connect.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>