3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>async_read_until (6 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="overload5.html" title="async_read_until (5 of 12 overloads)">
10 <link rel="next" href="overload7.html" title="async_read_until (7 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="overload5.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="overload7.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.overload6"></a><a class="link" href="overload6.html" title="async_read_until (6 of 12 overloads)">async_read_until
28 (6 of 12 overloads)</a>
29 </h4></div></div></div>
31 Start an asynchronous operation to read data into a streambuf until it
32 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>,
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 boost::asio::basic_streambuf< Allocator > & b,
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>);
45 This function is used to asynchronously read data into the specified streambuf
46 until the streambuf's get area contains the specified delimiter. The function
47 call always returns immediately. The asynchronous operation will continue
48 until one of the following conditions is true:
50 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
52 The get area of the streambuf contains the specified delimiter.
59 This operation is implemented in terms of zero or more calls to the stream's
60 async_read_some function, and is known as a <span class="emphasis"><em>composed operation</em></span>.
61 If the streambuf's get area already contains the delimiter, this asynchronous
62 operation completes immediately. The program must ensure that the stream
63 performs no other read operations (such as async_read, async_read_until,
64 the stream's async_read_some function, or any other composed operations
65 that perform reads) until this operation completes.
68 <a name="boost_asio.reference.async_read_until.overload6.h0"></a>
69 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload6.parameters"></a></span><a class="link" href="overload6.html#boost_asio.reference.async_read_until.overload6.parameters">Parameters</a>
71 <div class="variablelist">
72 <p class="title"><b></b></p>
73 <dl class="variablelist">
74 <dt><span class="term">s</span></dt>
76 The stream from which the data is to be read. The type must support
77 the AsyncReadStream concept.
79 <dt><span class="term">b</span></dt>
81 A streambuf object into which the data will be read. Ownership of
82 the streambuf is retained by the caller, which must guarantee that
83 it remains valid until the handler is called.
85 <dt><span class="term">delim</span></dt>
89 <dt><span class="term">handler</span></dt>
92 The handler to be called when the read operation completes. Copies
93 will be made of the handler as required. The function signature of
96 <pre class="programlisting">void handler(
97 // Result of operation.
98 const boost::system::error_code& error,
100 // The number of bytes in the streambuf's get
101 // area up to and including the delimiter.
102 // 0 if an error occurred.
103 std::size_t bytes_transferred
107 Regardless of whether the asynchronous operation completes immediately
108 or not, the handler will not be invoked from within this function.
109 On immediate completion, invocation of the handler will be performed
110 in a manner equivalent to using <a class="link" href="../post.html" title="post"><code class="computeroutput">post</code></a>.
116 <a name="boost_asio.reference.async_read_until.overload6.h1"></a>
117 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload6.remarks"></a></span><a class="link" href="overload6.html#boost_asio.reference.async_read_until.overload6.remarks">Remarks</a>
120 After a successful async_read_until operation, the streambuf may contain
121 additional data beyond the delimiter. An application will typically leave
122 that data in the streambuf for a subsequent async_read_until operation
126 <a name="boost_asio.reference.async_read_until.overload6.h2"></a>
127 <span class="phrase"><a name="boost_asio.reference.async_read_until.overload6.example"></a></span><a class="link" href="overload6.html#boost_asio.reference.async_read_until.overload6.example">Example</a>
130 To asynchronously read data into a streambuf until a newline is encountered:
132 <pre class="programlisting">boost::asio::streambuf b;
134 void handler(const boost::system::error_code& e, std::size_t size)
138 std::istream is(&b);
140 std::getline(is, line);
145 boost::asio::async_read_until(s, b, "\r\n", handler);
148 After the <code class="computeroutput">async_read_until</code> operation completes successfully,
149 the buffer <code class="computeroutput">b</code> contains the delimiter:
151 <pre class="programlisting">{ 'a', 'b', ..., 'c', '\r', '\n', 'd', 'e', ... }
154 The call to <code class="computeroutput">std::getline</code> then extracts the data up to and
155 including the newline (which is discarded), so that the string <code class="computeroutput">line</code>
158 <pre class="programlisting">{ 'a', 'b', ..., 'c', '\r' }
161 The remaining data is left in the buffer <code class="computeroutput">b</code> as follows:
163 <pre class="programlisting">{ 'd', 'e', ... }
166 This data may be the start of a new line, to be extracted by a subsequent
167 <code class="computeroutput">async_read_until</code> operation.
170 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
171 <td align="left"></td>
172 <td align="right"><div class="copyright-footer">Copyright © 2003-2019 Christopher M. Kohlhoff<p>
173 Distributed under the Boost Software License, Version 1.0. (See accompanying
174 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>)
179 <div class="spirit-nav">
180 <a accesskey="p" href="overload5.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="overload7.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>