• 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 (15 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="overload14.html" title="read_until (14 of 24 overloads)">
10<link rel="next" href="overload16.html" title="read_until (16 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="overload14.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="overload16.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.overload15"></a><a class="link" href="overload15.html" title="read_until (15 of 24 overloads)">read_until
28        (15 of 24 overloads)</a>
29</h4></div></div></div>
30<p>
31          Read data into a streambuf until a function object indicates a match.
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,
36    typename MatchCondition&gt;
37std::size_t read_until(
38    SyncReadStream &amp; s,
39    boost::asio::basic_streambuf&lt; Allocator &gt; &amp; b,
40    MatchCondition match_condition,
41    typename enable_if&lt; is_match_condition&lt; MatchCondition &gt;::value &gt;::type *  = 0);
42</pre>
43<p>
44          This function is used to read data into the specified streambuf until a
45          user-defined match condition function object, when applied to the data
46          contained in the streambuf, indicates a successful match. The call will
47          block until one of the following conditions is true:
48        </p>
49<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
50<li class="listitem">
51              The match condition function object returns a std::pair where the second
52              element evaluates to true.
53            </li>
54<li class="listitem">
55              An error occurred.
56            </li>
57</ul></div>
58<p>
59          This operation is implemented in terms of zero or more calls to the stream's
60          read_some function. If the match condition function object already indicates
61          a match, the function returns immediately.
62        </p>
63<h6>
64<a name="boost_asio.reference.read_until.overload15.h0"></a>
65          <span class="phrase"><a name="boost_asio.reference.read_until.overload15.parameters"></a></span><a class="link" href="overload15.html#boost_asio.reference.read_until.overload15.parameters">Parameters</a>
66        </h6>
67<div class="variablelist">
68<p class="title"><b></b></p>
69<dl class="variablelist">
70<dt><span class="term">s</span></dt>
71<dd><p>
72                The stream from which the data is to be read. The type must support
73                the SyncReadStream concept.
74              </p></dd>
75<dt><span class="term">b</span></dt>
76<dd><p>
77                A streambuf object into which the data will be read.
78              </p></dd>
79<dt><span class="term">match_condition</span></dt>
80<dd>
81<p>
82                The function object to be called to determine whether a match exists.
83                The signature of the function object must be:
84</p>
85<pre class="programlisting">pair&lt;iterator, bool&gt; match_condition(iterator begin, iterator end);
86</pre>
87<p>
88                where <code class="computeroutput">iterator</code> represents the type:
89</p>
90<pre class="programlisting">buffers_iterator&lt;basic_streambuf&lt;Allocator&gt;::const_buffers_type&gt;
91</pre>
92<p>
93                The iterator parameters <code class="computeroutput">begin</code> and <code class="computeroutput">end</code> define
94                the range of bytes to be scanned to determine whether there is a
95                match. The <code class="computeroutput">first</code> member of the return value is an iterator
96                marking one-past-the-end of the bytes that have been consumed by
97                the match function. This iterator is used to calculate the <code class="computeroutput">begin</code>
98                parameter for any subsequent invocation of the match condition. The
99                <code class="computeroutput">second</code> member of the return value is true if a match
100                has been found, false otherwise.
101              </p>
102</dd>
103</dl>
104</div>
105<h6>
106<a name="boost_asio.reference.read_until.overload15.h1"></a>
107          <span class="phrase"><a name="boost_asio.reference.read_until.overload15.return_value"></a></span><a class="link" href="overload15.html#boost_asio.reference.read_until.overload15.return_value">Return
108          Value</a>
109        </h6>
110<p>
111          The number of bytes in the streambuf's get area that have been fully consumed
112          by the match function.
113        </p>
114<h6>
115<a name="boost_asio.reference.read_until.overload15.h2"></a>
116          <span class="phrase"><a name="boost_asio.reference.read_until.overload15.exceptions"></a></span><a class="link" href="overload15.html#boost_asio.reference.read_until.overload15.exceptions">Exceptions</a>
117        </h6>
118<div class="variablelist">
119<p class="title"><b></b></p>
120<dl class="variablelist">
121<dt><span class="term">boost::system::system_error</span></dt>
122<dd><p>
123                Thrown on failure.
124              </p></dd>
125</dl>
126</div>
127<h6>
128<a name="boost_asio.reference.read_until.overload15.h3"></a>
129          <span class="phrase"><a name="boost_asio.reference.read_until.overload15.remarks"></a></span><a class="link" href="overload15.html#boost_asio.reference.read_until.overload15.remarks">Remarks</a>
130        </h6>
131<p>
132          After a successful read_until operation, the streambuf may contain additional
133          data beyond that which matched the function object. An application will
134          typically leave that data in the streambuf for a subsequent read_until
135          operation to examine.
136        </p>
137<p>
138          The default implementation of the <code class="computeroutput">is_match_condition</code> type
139          trait evaluates to true for function pointers and function objects with
140          a <code class="computeroutput">result_type</code> typedef. It must be specialised for other user-defined
141          function objects.
142        </p>
143<h6>
144<a name="boost_asio.reference.read_until.overload15.h4"></a>
145          <span class="phrase"><a name="boost_asio.reference.read_until.overload15.examples"></a></span><a class="link" href="overload15.html#boost_asio.reference.read_until.overload15.examples">Examples</a>
146        </h6>
147<p>
148          To read data into a streambuf until whitespace is encountered:
149        </p>
150<pre class="programlisting">typedef boost::asio::buffers_iterator&lt;
151    boost::asio::streambuf::const_buffers_type&gt; iterator;
152
153std::pair&lt;iterator, bool&gt;
154match_whitespace(iterator begin, iterator end)
155{
156  iterator i = begin;
157  while (i != end)
158    if (std::isspace(*i++))
159      return std::make_pair(i, true);
160  return std::make_pair(i, false);
161}
162...
163boost::asio::streambuf b;
164boost::asio::read_until(s, b, match_whitespace);
165</pre>
166<p>
167          To read data into a streambuf until a matching character is found:
168        </p>
169<pre class="programlisting">class match_char
170{
171public:
172  explicit match_char(char c) : c_(c) {}
173
174  template &lt;typename Iterator&gt;
175  std::pair&lt;Iterator, bool&gt; operator()(
176      Iterator begin, Iterator end) const
177  {
178    Iterator i = begin;
179    while (i != end)
180      if (c_ == *i++)
181        return std::make_pair(i, true);
182    return std::make_pair(i, false);
183  }
184
185private:
186  char c_;
187};
188
189namespace asio {
190  template &lt;&gt; struct is_match_condition&lt;match_char&gt;
191    : public boost::true_type {};
192} // namespace asio
193...
194boost::asio::streambuf b;
195boost::asio::read_until(s, b, match_char('a'));
196</pre>
197</div>
198<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
199<td align="left"></td>
200<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
201      Kohlhoff<p>
202        Distributed under the Boost Software License, Version 1.0. (See accompanying
203        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>)
204      </p>
205</div></td>
206</tr></table>
207<hr>
208<div class="spirit-nav">
209<a accesskey="p" href="overload14.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="overload16.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
210</div>
211</body>
212</html>
213