• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>read_until (19 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="overload18.html" title="read_until (18 of 24 overloads)">
10<link rel="next" href="overload20.html" title="read_until (20 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="overload18.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="overload20.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.overload19"></a><a class="link" href="overload19.html" title="read_until (19 of 24 overloads)">read_until
28        (19 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&lt;
35    typename <a class="link" href="../SyncReadStream.html" title="Buffer-oriented synchronous read stream requirements">SyncReadStream</a>,
36    typename <a class="link" href="../DynamicBuffer_v2.html" title="Dynamic buffer requirements (version 2)">DynamicBuffer_v2</a>&gt;
37std::size_t read_until(
38    SyncReadStream &amp; s,
39    DynamicBuffer_v2 buffers,
40    string_view delim,
41    typename enable_if&lt; is_dynamic_buffer_v2&lt; DynamicBuffer_v2 &gt;::value &gt;::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.overload19.h0"></a>
64          <span class="phrase"><a name="boost_asio.reference.read_until.overload19.parameters"></a></span><a class="link" href="overload19.html#boost_asio.reference.read_until.overload19.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 string.
81              </p></dd>
82</dl>
83</div>
84<h6>
85<a name="boost_asio.reference.read_until.overload19.h1"></a>
86          <span class="phrase"><a name="boost_asio.reference.read_until.overload19.return_value"></a></span><a class="link" href="overload19.html#boost_asio.reference.read_until.overload19.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.overload19.h2"></a>
95          <span class="phrase"><a name="boost_asio.reference.read_until.overload19.remarks"></a></span><a class="link" href="overload19.html#boost_asio.reference.read_until.overload19.remarks">Remarks</a>
96        </h6>
97<p>
98          After a successful read_until operation, the dynamic buffer sequence may
99          contain additional data beyond the delimiter. An application will typically
100          leave that data in the dynamic buffer sequence for a subsequent read_until
101          operation to examine.
102        </p>
103<h6>
104<a name="boost_asio.reference.read_until.overload19.h3"></a>
105          <span class="phrase"><a name="boost_asio.reference.read_until.overload19.example"></a></span><a class="link" href="overload19.html#boost_asio.reference.read_until.overload19.example">Example</a>
106        </h6>
107<p>
108          To read data into a <code class="computeroutput">std::string</code> until a CR-LF sequence is
109          encountered:
110        </p>
111<pre class="programlisting">std::string data;
112std::size_t n = boost::asio::read_until(s,
113    boost::asio::dynamic_buffer(data), "\r\n");
114std::string line = data.substr(0, n);
115data.erase(0, n);
116</pre>
117<p>
118          After the <code class="computeroutput">read_until</code> operation completes successfully, the
119          string <code class="computeroutput">data</code> contains the delimiter:
120        </p>
121<pre class="programlisting">{ 'a', 'b', ..., 'c', '\r', '\n', 'd', 'e', ... }
122</pre>
123<p>
124          The call to <code class="computeroutput">substr</code> then extracts the data up to and including
125          the delimiter, so that the string <code class="computeroutput">line</code> contains:
126        </p>
127<pre class="programlisting">{ 'a', 'b', ..., 'c', '\r', '\n' }
128</pre>
129<p>
130          After the call to <code class="computeroutput">erase</code>, the remaining data is left in the
131          buffer <code class="computeroutput">b</code> as follows:
132        </p>
133<pre class="programlisting">{ 'd', 'e', ... }
134</pre>
135<p>
136          This data may be the start of a new line, to be extracted by a subsequent
137          <code class="computeroutput">read_until</code> operation.
138        </p>
139</div>
140<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
141<td align="left"></td>
142<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
143      Kohlhoff<p>
144        Distributed under the Boost Software License, Version 1.0. (See accompanying
145        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>)
146      </p>
147</div></td>
148</tr></table>
149<hr>
150<div class="spirit-nav">
151<a accesskey="p" href="overload18.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="overload20.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
152</div>
153</body>
154</html>
155