1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 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)"> 11</head> 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> 20</tr></table> 21<hr> 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> 24</div> 25<div class="section"> 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> 30<p> 31 Start an asynchronous operation to read data into a dynamic buffer sequence 32 until it contains a specified delimiter. 33 </p> 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, 41 char delim, 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); 44</pre> 45<p> 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 50 is true: 51 </p> 52<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 53<li class="listitem"> 54 The get area of the dynamic buffer sequence contains the specified 55 delimiter. 56 </li> 57<li class="listitem"> 58 An error occurred. 59 </li> 60</ul></div> 61<p> 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. 69 </p> 70<h6> 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> 73 </h6> 74<div class="variablelist"> 75<p class="title"><b></b></p> 76<dl class="variablelist"> 77<dt><span class="term">s</span></dt> 78<dd><p> 79 The stream from which the data is to be read. The type must support 80 the AsyncReadStream concept. 81 </p></dd> 82<dt><span class="term">buffers</span></dt> 83<dd><p> 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. 88 </p></dd> 89<dt><span class="term">delim</span></dt> 90<dd><p> 91 The delimiter character. 92 </p></dd> 93<dt><span class="term">handler</span></dt> 94<dd> 95<p> 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 98 the handler must be: 99</p> 100<pre class="programlisting">void handler( 101 // Result of operation. 102 const boost::system::error_code& error, 103 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 108); 109</pre> 110<p> 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>. 115 </p> 116</dd> 117</dl> 118</div> 119<h6> 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> 122 </h6> 123<p> 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. 128 </p> 129<h6> 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> 132 </h6> 133<p> 134 To asynchronously read data into a <code class="computeroutput">std::string</code> until a newline 135 is encountered: 136 </p> 137<pre class="programlisting">std::string data; 138... 139void handler(const boost::system::error_code& e, std::size_t size) 140{ 141 if (!e) 142 { 143 std::string line = data.substr(0, n); 144 data.erase(0, n); 145 ... 146 } 147} 148... 149boost::asio::async_read_until(s, data, '\n', handler); 150</pre> 151<p> 152 After the <code class="computeroutput">async_read_until</code> operation completes successfully, 153 the buffer <code class="computeroutput">data</code> contains the delimiter: 154 </p> 155<pre class="programlisting">{ 'a', 'b', ..., 'c', '\n', 'd', 'e', ... } 156</pre> 157<p> 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: 160 </p> 161<pre class="programlisting">{ 'a', 'b', ..., 'c', '\n' } 162</pre> 163<p> 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: 166 </p> 167<pre class="programlisting">{ 'd', 'e', ... } 168</pre> 169<p> 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. 172 </p> 173</div> 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-2020 Christopher M. 177 Kohlhoff<p> 178 Distributed under the Boost Software License, Version 1.0. (See accompanying 179 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>) 180 </p> 181</div></td> 182</tr></table> 183<hr> 184<div class="spirit-nav"> 185<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> 186</div> 187</body> 188</html> 189