3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>read_until (1 of 8 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 8 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="../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>
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 8 overloads)">read_until
28 (1 of 8 overloads)</a>
29 </h4></div></div></div>
31 Read data into a streambuf until it contains a specified delimiter.
33 <pre class="programlisting"><span class="keyword">template</span><span class="special"><</span>
34 <span class="keyword">typename</span> <a class="link" href="../SyncReadStream.html" title="Buffer-oriented synchronous read stream requirements">SyncReadStream</a><span class="special">,</span>
35 <span class="keyword">typename</span> <span class="identifier">Allocator</span><span class="special">></span>
36 <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">read_until</span><span class="special">(</span>
37 <span class="identifier">SyncReadStream</span> <span class="special">&</span> <span class="identifier">s</span><span class="special">,</span>
38 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">basic_streambuf</span><span class="special"><</span> <span class="identifier">Allocator</span> <span class="special">></span> <span class="special">&</span> <span class="identifier">b</span><span class="special">,</span>
39 <span class="keyword">char</span> <span class="identifier">delim</span><span class="special">);</span>
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:
46 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
48 The get area of the streambuf contains the specified delimiter.
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.
60 <a name="boost_asio.reference.read_until.overload1.h0"></a>
61 <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>
63 <div class="variablelist">
64 <p class="title"><b></b></p>
65 <dl class="variablelist">
66 <dt><span class="term">s</span></dt>
68 The stream from which the data is to be read. The type must support
69 the SyncReadStream concept.
71 <dt><span class="term">b</span></dt>
73 A streambuf object into which the data will be read.
75 <dt><span class="term">delim</span></dt>
77 The delimiter character.
82 <a name="boost_asio.reference.read_until.overload1.h1"></a>
83 <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 The number of bytes in the streambuf's get area up to and including the
91 <a name="boost_asio.reference.read_until.overload1.h2"></a>
92 <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>
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>
104 <a name="boost_asio.reference.read_until.overload1.h3"></a>
105 <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>
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.
113 <a name="boost_asio.reference.read_until.overload1.h4"></a>
114 <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>
117 To read data into a streambuf until a newline is encountered:
119 <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">streambuf</span> <span class="identifier">b</span><span class="special">;</span>
120 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">read_until</span><span class="special">(</span><span class="identifier">s</span><span class="special">,</span> <span class="identifier">b</span><span class="special">,</span> <span class="char">'\n'</span><span class="special">);</span>
121 <span class="identifier">std</span><span class="special">::</span><span class="identifier">istream</span> <span class="identifier">is</span><span class="special">(&</span><span class="identifier">b</span><span class="special">);</span>
122 <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">line</span><span class="special">;</span>
123 <span class="identifier">std</span><span class="special">::</span><span class="identifier">getline</span><span class="special">(</span><span class="identifier">is</span><span class="special">,</span> <span class="identifier">line</span><span class="special">);</span>
126 After the <code class="computeroutput"><span class="identifier">read_until</span></code> operation
127 completes successfully, the buffer <code class="computeroutput"><span class="identifier">b</span></code>
128 contains the delimiter:
130 <pre class="programlisting"><span class="special">{</span> <span class="char">'a'</span><span class="special">,</span> <span class="char">'b'</span><span class="special">,</span> <span class="special">...,</span> <span class="char">'c'</span><span class="special">,</span> <span class="char">'\n'</span><span class="special">,</span> <span class="char">'d'</span><span class="special">,</span> <span class="char">'e'</span><span class="special">,</span> <span class="special">...</span> <span class="special">}</span>
133 The call to <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">getline</span></code> then extracts the data up to
134 and including the delimiter, so that the string <code class="computeroutput"><span class="identifier">line</span></code>
137 <pre class="programlisting"><span class="special">{</span> <span class="char">'a'</span><span class="special">,</span> <span class="char">'b'</span><span class="special">,</span> <span class="special">...,</span> <span class="char">'c'</span><span class="special">,</span> <span class="char">'\n'</span> <span class="special">}</span>
140 The remaining data is left in the buffer <code class="computeroutput"><span class="identifier">b</span></code>
143 <pre class="programlisting"><span class="special">{</span> <span class="char">'d'</span><span class="special">,</span> <span class="char">'e'</span><span class="special">,</span> <span class="special">...</span> <span class="special">}</span>
146 This data may be the start of a new line, to be extracted by a subsequent
147 <code class="computeroutput"><span class="identifier">read_until</span></code> operation.
150 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
151 <td align="left"></td>
152 <td align="right"><div class="copyright-footer">Copyright © 2003-2017 Christopher M. Kohlhoff<p>
153 Distributed under the Boost Software License, Version 1.0. (See accompanying
154 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>)
159 <div class="spirit-nav">
160 <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>