3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>async_read_until (4 of 12 overloads)</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="../async_read_until.html" title="async_read_until">
9 <link rel="prev" href="overload3.html" title="async_read_until (3 of 12 overloads)">
10 <link rel="next" href="overload5.html" title="async_read_until (5 of 12 overloads)">
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="overload3.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../async_read_until.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="overload5.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h4 class="title">
27 <a name="boost_asio.reference.async_read_until.overload4"></a><a class="link" href="overload4.html" title="async_read_until (4 of 12 overloads)">async_read_until
28 (4 of 12 overloads)</a>
29 </h4></div></div></div>
31 Start an asynchronous operation to read data into a dynamic buffer sequence
32 until a function object indicates a match.
34 <pre class="programlisting">template<
35 typename <a class="link" href="../AsyncReadStream.html" title="Buffer-oriented asynchronous read stream requirements">AsyncReadStream</a>,
36 typename <a class="link" href="../DynamicBuffer_v1.html" title="Dynamic buffer requirements (version 1)">DynamicBuffer_v1</a>,
37 typename MatchCondition,
38 typename <a class="link" href="../ReadHandler.html" title="Read handler requirements">ReadHandler</a> = <a class="link" href="../asynchronous_operations.html#boost_asio.reference.asynchronous_operations.default_completion_tokens"><span class="emphasis"><em>DEFAULT</em></span></a>>
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_read_until(
40 AsyncReadStream & s,
41 DynamicBuffer_v1 && buffers,
42 MatchCondition match_condition,
43 ReadHandler && handler = <a class="link" href="../asynchronous_operations.html#boost_asio.reference.asynchronous_operations.default_completion_tokens"><span class="emphasis"><em>DEFAULT</em></span></a>,
44 typename enable_if< is_match_condition< MatchCondition >::value &&is_dynamic_buffer_v1< typename decay< DynamicBuffer_v1 >::type >::value &&!is_dynamic_buffer_v2< typename decay< DynamicBuffer_v1 >::type >::value >::type * = 0);
47 This function is used to asynchronously read data into the specified dynamic
48 buffer sequence until a user-defined match condition function object, when
49 applied to the data contained in the dynamic buffer sequence, indicates
50 a successful match. The function call always returns immediately. The asynchronous
51 operation will continue until one of the following conditions is true:
53 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
55 The match condition function object returns a std::pair where the second
56 element evaluates to true.
63 This operation is implemented in terms of zero or more calls to the stream's
64 async_read_some function, and is known as a <span class="emphasis"><em>composed operation</em></span>.
65 If the match condition function object already indicates a match, this
66 asynchronous operation completes immediately. The program must ensure that
67 the stream performs no other read operations (such as async_read, async_read_until,
68 the stream's async_read_some function, or any other composed operations
69 that perform reads) until this operation completes.
72 <a name="boost_asio.reference.async_read_until.overload4.h0"></a>
73 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload4.parameters"></a></span><a class="link" href="overload4.html#boost_asio.reference.async_read_until.overload4.parameters">Parameters</a>
75 <div class="variablelist">
76 <p class="title"><b></b></p>
77 <dl class="variablelist">
78 <dt><span class="term">s</span></dt>
80 The stream from which the data is to be read. The type must support
81 the AsyncReadStream concept.
83 <dt><span class="term">buffers</span></dt>
85 The dynamic buffer sequence into which the data will be read. Although
86 the buffers object may be copied as necessary, ownership of the underlying
87 memory blocks is retained by the caller, which must guarantee that
88 they remain valid until the handler is called.
90 <dt><span class="term">match_condition</span></dt>
93 The function object to be called to determine whether a match exists.
94 The signature of the function object must be:
96 <pre class="programlisting">pair<iterator, bool> match_condition(iterator begin, iterator end);
99 where <code class="computeroutput">iterator</code> represents the type:
101 <pre class="programlisting">buffers_iterator<typename DynamicBuffer_v1::const_buffers_type>
104 The iterator parameters <code class="computeroutput">begin</code> and <code class="computeroutput">end</code> define
105 the range of bytes to be scanned to determine whether there is a
106 match. The <code class="computeroutput">first</code> member of the return value is an iterator
107 marking one-past-the-end of the bytes that have been consumed by
108 the match function. This iterator is used to calculate the <code class="computeroutput">begin</code>
109 parameter for any subsequent invocation of the match condition. The
110 <code class="computeroutput">second</code> member of the return value is true if a match
111 has been found, false otherwise.
114 <dt><span class="term">handler</span></dt>
117 The handler to be called when the read operation completes. Copies
118 will be made of the handler as required. The function signature of
121 <pre class="programlisting">void handler(
122 // Result of operation.
123 const boost::system::error_code& error,
125 // The number of bytes in the dynamic buffer sequence's
126 // get area that have been fully consumed by the match
127 // function. O if an error occurred.
128 std::size_t bytes_transferred
132 Regardless of whether the asynchronous operation completes immediately
133 or not, the handler will not be invoked from within this function.
134 On immediate completion, invocation of the handler will be performed
135 in a manner equivalent to using <a class="link" href="../post.html" title="post"><code class="computeroutput">post</code></a>.
141 <a name="boost_asio.reference.async_read_until.overload4.h1"></a>
142 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload4.remarks"></a></span><a class="link" href="overload4.html#boost_asio.reference.async_read_until.overload4.remarks">Remarks</a>
145 After a successful async_read_until operation, the dynamic buffer sequence
146 may contain additional data beyond that which matched the function object.
147 An application will typically leave that data in the dynamic buffer sequence
148 for a subsequent async_read_until operation to examine.
151 The default implementation of the <code class="computeroutput">is_match_condition</code> type
152 trait evaluates to true for function pointers and function objects with
153 a <code class="computeroutput">result_type</code> typedef. It must be specialised for other user-defined
157 <a name="boost_asio.reference.async_read_until.overload4.h2"></a>
158 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload4.examples"></a></span><a class="link" href="overload4.html#boost_asio.reference.async_read_until.overload4.examples">Examples</a>
161 To asynchronously read data into a <code class="computeroutput">std::string</code> until whitespace
164 <pre class="programlisting">typedef boost::asio::buffers_iterator<
165 boost::asio::const_buffers_1> iterator;
167 std::pair<iterator, bool>
168 match_whitespace(iterator begin, iterator end)
172 if (std::isspace(*i++))
173 return std::make_pair(i, true);
174 return std::make_pair(i, false);
177 void handler(const boost::system::error_code& e, std::size_t size);
180 boost::asio::async_read_until(s, data, match_whitespace, handler);
183 To asynchronously read data into a <code class="computeroutput">std::string</code> until a matching
186 <pre class="programlisting">class match_char
189 explicit match_char(char c) : c_(c) {}
191 template <typename Iterator>
192 std::pair<Iterator, bool> operator()(
193 Iterator begin, Iterator end) const
198 return std::make_pair(i, true);
199 return std::make_pair(i, false);
207 template <> struct is_match_condition<match_char>
208 : public boost::true_type {};
211 void handler(const boost::system::error_code& e, std::size_t size);
214 boost::asio::async_read_until(s, data, match_char('a'), handler);
217 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
218 <td align="left"></td>
219 <td align="right"><div class="copyright-footer">Copyright © 2003-2019 Christopher M. Kohlhoff<p>
220 Distributed under the Boost Software License, Version 1.0. (See accompanying
221 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>)
226 <div class="spirit-nav">
227 <a accesskey="p" href="overload3.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../async_read_until.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="overload5.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>