3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>async_read_until (9 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="overload8.html" title="async_read_until (8 of 12 overloads)">
10 <link rel="next" href="overload10.html" title="async_read_until (10 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="overload8.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="overload10.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.overload9"></a><a class="link" href="overload9.html" title="async_read_until (9 of 12 overloads)">async_read_until
28 (9 of 12 overloads)</a>
29 </h4></div></div></div>
31 Start an asynchronous operation to read data into a dynamic buffer sequence
32 until it contains a specified delimiter.
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_v2.html" title="Dynamic buffer requirements (version 2)">DynamicBuffer_v2</a>,
37 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>>
38 <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(
39 AsyncReadStream & s,
40 DynamicBuffer_v2 buffers,
42 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>,
43 typename enable_if< is_dynamic_buffer_v2< DynamicBuffer_v2 >::value >::type * = 0);
46 This function is used to asynchronously read data into the specified dynamic
47 buffer sequence until the dynamic buffer sequence's get area contains the
48 specified delimiter. The function call always returns immediately. The
49 asynchronous operation will continue until one of the following conditions
52 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
54 The get area of the dynamic buffer sequence contains the specified
62 This operation is implemented in terms of zero or more calls to the stream's
63 async_read_some function, and is known as a <span class="emphasis"><em>composed operation</em></span>.
64 If the dynamic buffer sequence's get area already contains the delimiter,
65 this asynchronous operation completes immediately. The program must ensure
66 that the stream performs no other read operations (such as async_read,
67 async_read_until, the stream's async_read_some function, or any other composed
68 operations that perform reads) until this operation completes.
71 <a name="boost_asio.reference.async_read_until.overload9.h0"></a>
72 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload9.parameters"></a></span><a class="link" href="overload9.html#boost_asio.reference.async_read_until.overload9.parameters">Parameters</a>
74 <div class="variablelist">
75 <p class="title"><b></b></p>
76 <dl class="variablelist">
77 <dt><span class="term">s</span></dt>
79 The stream from which the data is to be read. The type must support
80 the AsyncReadStream concept.
82 <dt><span class="term">buffers</span></dt>
84 The dynamic buffer sequence into which the data will be read. Although
85 the buffers object may be copied as necessary, ownership of the underlying
86 memory blocks is retained by the caller, which must guarantee that
87 they remain valid until the handler is called.
89 <dt><span class="term">delim</span></dt>
91 The delimiter character.
93 <dt><span class="term">handler</span></dt>
96 The handler to be called when the read operation completes. Copies
97 will be made of the handler as required. The function signature of
100 <pre class="programlisting">void handler(
101 // Result of operation.
102 const boost::system::error_code& error,
104 // The number of bytes in the dynamic buffer sequence's
105 // get area up to and including the delimiter.
106 // 0 if an error occurred.
107 std::size_t bytes_transferred
111 Regardless of whether the asynchronous operation completes immediately
112 or not, the handler will not be invoked from within this function.
113 On immediate completion, invocation of the handler will be performed
114 in a manner equivalent to using <a class="link" href="../post.html" title="post"><code class="computeroutput">post</code></a>.
120 <a name="boost_asio.reference.async_read_until.overload9.h1"></a>
121 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload9.remarks"></a></span><a class="link" href="overload9.html#boost_asio.reference.async_read_until.overload9.remarks">Remarks</a>
124 After a successful async_read_until operation, the dynamic buffer sequence
125 may contain additional data beyond the delimiter. An application will typically
126 leave that data in the dynamic buffer sequence for a subsequent async_read_until
127 operation to examine.
130 <a name="boost_asio.reference.async_read_until.overload9.h2"></a>
131 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload9.example"></a></span><a class="link" href="overload9.html#boost_asio.reference.async_read_until.overload9.example">Example</a>
134 To asynchronously read data into a <code class="computeroutput">std::string</code> until a newline
137 <pre class="programlisting">std::string data;
139 void handler(const boost::system::error_code& e, std::size_t size)
143 std::string line = data.substr(0, n);
149 boost::asio::async_read_until(s, data, '\n', handler);
152 After the <code class="computeroutput">async_read_until</code> operation completes successfully,
153 the buffer <code class="computeroutput">data</code> contains the delimiter:
155 <pre class="programlisting">{ 'a', 'b', ..., 'c', '\n', 'd', 'e', ... }
158 The call to <code class="computeroutput">substr</code> then extracts the data up to and including
159 the delimiter, so that the string <code class="computeroutput">line</code> contains:
161 <pre class="programlisting">{ 'a', 'b', ..., 'c', '\n' }
164 After the call to <code class="computeroutput">erase</code>, the remaining data is left in the
165 buffer <code class="computeroutput">data</code> as follows:
167 <pre class="programlisting">{ 'd', 'e', ... }
170 This data may be the start of a new line, to be extracted by a subsequent
171 <code class="computeroutput">async_read_until</code> operation.
174 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
175 <td align="left"></td>
176 <td align="right"><div class="copyright-footer">Copyright © 2003-2019 Christopher M. Kohlhoff<p>
177 Distributed under the Boost Software License, Version 1.0. (See accompanying
178 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>)
183 <div class="spirit-nav">
184 <a accesskey="p" href="overload8.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="overload10.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>