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