1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>read_until (1 of 24 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="../read_until.html" title="read_until"> 9<link rel="prev" href="../read_until.html" title="read_until"> 10<link rel="next" href="overload2.html" title="read_until (2 of 24 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="../read_until.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../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="overload2.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.read_until.overload1"></a><a class="link" href="overload1.html" title="read_until (1 of 24 overloads)">read_until 28 (1 of 24 overloads)</a> 29</h4></div></div></div> 30<p> 31 Read data into a dynamic buffer sequence until it contains a specified 32 delimiter. 33 </p> 34<pre class="programlisting">template< 35 typename <a class="link" href="../SyncReadStream.html" title="Buffer-oriented synchronous read stream requirements">SyncReadStream</a>, 36 typename <a class="link" href="../DynamicBuffer_v1.html" title="Dynamic buffer requirements (version 1)">DynamicBuffer_v1</a>> 37std::size_t read_until( 38 SyncReadStream & s, 39 DynamicBuffer_v1 && buffers, 40 char delim, 41 typename enable_if< is_dynamic_buffer_v1< typename decay< DynamicBuffer_v1 >::type >::value &&!is_dynamic_buffer_v2< typename decay< DynamicBuffer_v1 >::type >::value >::type * = 0); 42</pre> 43<p> 44 This function is used to read data into the specified dynamic buffer sequence 45 until the dynamic buffer sequence's get area contains the specified delimiter. 46 The call will block until one of the following conditions is true: 47 </p> 48<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 49<li class="listitem"> 50 The get area of the dynamic buffer sequence contains the specified 51 delimiter. 52 </li> 53<li class="listitem"> 54 An error occurred. 55 </li> 56</ul></div> 57<p> 58 This operation is implemented in terms of zero or more calls to the stream's 59 read_some function. If the dynamic buffer sequence's get area already contains 60 the delimiter, the function returns immediately. 61 </p> 62<h6> 63<a name="boost_asio.reference.read_until.overload1.h0"></a> 64 <span class="phrase"><a name="boost_asio.reference.read_until.overload1.parameters"></a></span><a class="link" href="overload1.html#boost_asio.reference.read_until.overload1.parameters">Parameters</a> 65 </h6> 66<div class="variablelist"> 67<p class="title"><b></b></p> 68<dl class="variablelist"> 69<dt><span class="term">s</span></dt> 70<dd><p> 71 The stream from which the data is to be read. The type must support 72 the SyncReadStream concept. 73 </p></dd> 74<dt><span class="term">buffers</span></dt> 75<dd><p> 76 The dynamic buffer sequence into which the data will be read. 77 </p></dd> 78<dt><span class="term">delim</span></dt> 79<dd><p> 80 The delimiter character. 81 </p></dd> 82</dl> 83</div> 84<h6> 85<a name="boost_asio.reference.read_until.overload1.h1"></a> 86 <span class="phrase"><a name="boost_asio.reference.read_until.overload1.return_value"></a></span><a class="link" href="overload1.html#boost_asio.reference.read_until.overload1.return_value">Return 87 Value</a> 88 </h6> 89<p> 90 The number of bytes in the dynamic buffer sequence's get area up to and 91 including the delimiter. 92 </p> 93<h6> 94<a name="boost_asio.reference.read_until.overload1.h2"></a> 95 <span class="phrase"><a name="boost_asio.reference.read_until.overload1.exceptions"></a></span><a class="link" href="overload1.html#boost_asio.reference.read_until.overload1.exceptions">Exceptions</a> 96 </h6> 97<div class="variablelist"> 98<p class="title"><b></b></p> 99<dl class="variablelist"> 100<dt><span class="term">boost::system::system_error</span></dt> 101<dd><p> 102 Thrown on failure. 103 </p></dd> 104</dl> 105</div> 106<h6> 107<a name="boost_asio.reference.read_until.overload1.h3"></a> 108 <span class="phrase"><a name="boost_asio.reference.read_until.overload1.remarks"></a></span><a class="link" href="overload1.html#boost_asio.reference.read_until.overload1.remarks">Remarks</a> 109 </h6> 110<p> 111 After a successful read_until operation, the dynamic buffer sequence may 112 contain additional data beyond the delimiter. An application will typically 113 leave that data in the dynamic buffer sequence for a subsequent read_until 114 operation to examine. 115 </p> 116<h6> 117<a name="boost_asio.reference.read_until.overload1.h4"></a> 118 <span class="phrase"><a name="boost_asio.reference.read_until.overload1.example"></a></span><a class="link" href="overload1.html#boost_asio.reference.read_until.overload1.example">Example</a> 119 </h6> 120<p> 121 To read data into a <code class="computeroutput">std::string</code> until a newline is encountered: 122 </p> 123<pre class="programlisting">std::string data; 124std::size_t n = boost::asio::read_until(s, 125 boost::asio::dynamic_buffer(data), '\n'); 126std::string line = data.substr(0, n); 127data.erase(0, n); 128</pre> 129<p> 130 After the <code class="computeroutput">read_until</code> operation completes successfully, the 131 string <code class="computeroutput">data</code> contains the delimiter: 132 </p> 133<pre class="programlisting">{ 'a', 'b', ..., 'c', '\n', 'd', 'e', ... } 134</pre> 135<p> 136 The call to <code class="computeroutput">substr</code> then extracts the data up to and including 137 the delimiter, so that the string <code class="computeroutput">line</code> contains: 138 </p> 139<pre class="programlisting">{ 'a', 'b', ..., 'c', '\n' } 140</pre> 141<p> 142 After the call to <code class="computeroutput">erase</code>, the remaining data is left in the 143 buffer <code class="computeroutput">b</code> as follows: 144 </p> 145<pre class="programlisting">{ 'd', 'e', ... } 146</pre> 147<p> 148 This data may be the start of a new line, to be extracted by a subsequent 149 <code class="computeroutput">read_until</code> operation. 150 </p> 151</div> 152<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 153<td align="left"></td> 154<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 155 Kohlhoff<p> 156 Distributed under the Boost Software License, Version 1.0. (See accompanying 157 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>) 158 </p> 159</div></td> 160</tr></table> 161<hr> 162<div class="spirit-nav"> 163<a accesskey="p" href="../read_until.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../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="overload2.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 164</div> 165</body> 166</html> 167