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