3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>async_read_until (8 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="overload7.html" title="async_read_until (7 of 12 overloads)">
10 <link rel="next" href="overload9.html" title="async_read_until (9 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="overload7.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="overload9.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.overload8"></a><a class="link" href="overload8.html" title="async_read_until (8 of 12 overloads)">async_read_until
28 (8 of 12 overloads)</a>
29 </h4></div></div></div>
31 Start an asynchronous operation to read data into a streambuf until a function
32 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>,
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 boost::asio::basic_streambuf< Allocator > & b,
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 >::type * = 0);
47 This function is used to asynchronously read data into the specified streambuf
48 until a user-defined match condition function object, when applied to the
49 data contained in the streambuf, indicates a successful match. The function
50 call always returns immediately. The asynchronous operation will continue
51 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.overload8.h0"></a>
73 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload8.parameters"></a></span><a class="link" href="overload8.html#boost_asio.reference.async_read_until.overload8.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">b</span></dt>
85 A streambuf object into which the data will be read.
87 <dt><span class="term">match_condition</span></dt>
90 The function object to be called to determine whether a match exists.
91 The signature of the function object must be:
93 <pre class="programlisting">pair<iterator, bool> match_condition(iterator begin, iterator end);
96 where <code class="computeroutput">iterator</code> represents the type:
98 <pre class="programlisting">buffers_iterator<basic_streambuf<Allocator>::const_buffers_type>
101 The iterator parameters <code class="computeroutput">begin</code> and <code class="computeroutput">end</code> define
102 the range of bytes to be scanned to determine whether there is a
103 match. The <code class="computeroutput">first</code> member of the return value is an iterator
104 marking one-past-the-end of the bytes that have been consumed by
105 the match function. This iterator is used to calculate the <code class="computeroutput">begin</code>
106 parameter for any subsequent invocation of the match condition. The
107 <code class="computeroutput">second</code> member of the return value is true if a match
108 has been found, false otherwise.
111 <dt><span class="term">handler</span></dt>
114 The handler to be called when the read operation completes. Copies
115 will be made of the handler as required. The function signature of
118 <pre class="programlisting">void handler(
119 // Result of operation.
120 const boost::system::error_code& error,
122 // The number of bytes in the streambuf's get
123 // area that have been fully consumed by the
124 // match function. O if an error occurred.
125 std::size_t bytes_transferred
129 Regardless of whether the asynchronous operation completes immediately
130 or not, the handler will not be invoked from within this function.
131 On immediate completion, invocation of the handler will be performed
132 in a manner equivalent to using <a class="link" href="../post.html" title="post"><code class="computeroutput">post</code></a>.
138 <a name="boost_asio.reference.async_read_until.overload8.h1"></a>
139 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload8.remarks"></a></span><a class="link" href="overload8.html#boost_asio.reference.async_read_until.overload8.remarks">Remarks</a>
142 After a successful async_read_until operation, the streambuf may contain
143 additional data beyond that which matched the function object. An application
144 will typically leave that data in the streambuf for a subsequent async_read_until
145 operation to examine.
148 The default implementation of the <code class="computeroutput">is_match_condition</code> type
149 trait evaluates to true for function pointers and function objects with
150 a <code class="computeroutput">result_type</code> typedef. It must be specialised for other user-defined
154 <a name="boost_asio.reference.async_read_until.overload8.h2"></a>
155 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload8.examples"></a></span><a class="link" href="overload8.html#boost_asio.reference.async_read_until.overload8.examples">Examples</a>
158 To asynchronously read data into a streambuf until whitespace is encountered:
160 <pre class="programlisting">typedef boost::asio::buffers_iterator<
161 boost::asio::streambuf::const_buffers_type> iterator;
163 std::pair<iterator, bool>
164 match_whitespace(iterator begin, iterator end)
168 if (std::isspace(*i++))
169 return std::make_pair(i, true);
170 return std::make_pair(i, false);
173 void handler(const boost::system::error_code& e, std::size_t size);
175 boost::asio::streambuf b;
176 boost::asio::async_read_until(s, b, match_whitespace, handler);
179 To asynchronously read data into a streambuf until a matching character
182 <pre class="programlisting">class match_char
185 explicit match_char(char c) : c_(c) {}
187 template <typename Iterator>
188 std::pair<Iterator, bool> operator()(
189 Iterator begin, Iterator end) const
194 return std::make_pair(i, true);
195 return std::make_pair(i, false);
203 template <> struct is_match_condition<match_char>
204 : public boost::true_type {};
207 void handler(const boost::system::error_code& e, std::size_t size);
209 boost::asio::streambuf b;
210 boost::asio::async_read_until(s, b, match_char('a'), handler);
213 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
214 <td align="left"></td>
215 <td align="right"><div class="copyright-footer">Copyright © 2003-2019 Christopher M. Kohlhoff<p>
216 Distributed under the Boost Software License, Version 1.0. (See accompanying
217 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>)
222 <div class="spirit-nav">
223 <a accesskey="p" href="overload7.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="overload9.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>