Imported Upstream version 1.64.0
[platform/upstream/boost.git] / doc / html / boost_asio / reference / read_until / overload1.html
1 <html>
2 <head>
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)">
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 8 overloads)">read_until
28         (1 of 8 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"><span class="keyword">template</span><span class="special">&lt;</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">&gt;</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">&amp;</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">&lt;</span> <span class="identifier">Allocator</span> <span class="special">&gt;</span> <span class="special">&amp;</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>
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.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>
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.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
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.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>
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.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>
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.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>
115         </h6>
116 <p>
117           To read data into a streambuf until a newline is encountered:
118         </p>
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">(&amp;</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>
124 </pre>
125 <p>
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:
129         </p>
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>
131 </pre>
132 <p>
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>
135           contains:
136         </p>
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>
138 </pre>
139 <p>
140           The remaining data is left in the buffer <code class="computeroutput"><span class="identifier">b</span></code>
141           as follows:
142         </p>
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>
144 </pre>
145 <p>
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.
148         </p>
149 </div>
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 &#169; 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>)
155       </p>
156 </div></td>
157 </tr></table>
158 <hr>
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>
161 </div>
162 </body>
163 </html>