• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>websocket::stream::async_read</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="../../../index.html" title="Chapter 1. Boost.Beast">
8<link rel="up" href="../boost__beast__websocket__stream.html" title="websocket::stream">
9<link rel="prev" href="read/overload2.html" title="websocket::stream::read (2 of 2 overloads)">
10<link rel="next" href="read_some.html" title="websocket::stream::read_some">
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/overload2.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost__beast__websocket__stream.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="read_some.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h5 class="title">
27<a name="beast.ref.boost__beast__websocket__stream.async_read"></a><a class="link" href="async_read.html" title="websocket::stream::async_read">websocket::stream::async_read</a>
28</h5></div></div></div>
29<p>
30          <a class="indexterm" name="idm46057518306688"></a>
31        </p>
32<p>
33          Read a complete message asynchronously.
34        </p>
35<h6>
36<a name="beast.ref.boost__beast__websocket__stream.async_read.h0"></a>
37          <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.async_read.synopsis"></a></span><a class="link" href="async_read.html#beast.ref.boost__beast__websocket__stream.async_read.synopsis">Synopsis</a>
38        </h6>
39<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span>
40    <span class="keyword">class</span> <a class="link" href="../../concepts/DynamicBuffer.html" title="DynamicBuffer"><span class="emphasis"><em>DynamicBuffer</em></span></a><span class="special">,</span>
41    <span class="keyword">class</span> <a href="../../../../../../../doc/html/boost_asio/reference/ReadHandler.html" target="_top"><span class="emphasis"><em>ReadHandler</em></span></a> <span class="special">=</span> <span class="identifier">net</span><span class="special">::</span><span class="identifier">default_completion_token_t</span><span class="special">&lt;</span>                <a class="link" href="executor_type.html" title="websocket::stream::executor_type">executor_type</a><span class="special">&gt;&gt;</span>
42<a href="../../../../../../../doc/html/boost_asio/reference/asynchronous_operations.html#boost_asio.reference.asynchronous_operations.automatic_deduction_of_initiating_function_return_type" target="_top"><span class="emphasis"><em>DEDUCED</em></span></a>
43<span class="identifier">async_read</span><span class="special">(</span>
44    <span class="identifier">DynamicBuffer</span><span class="special">&amp;</span> <span class="identifier">buffer</span><span class="special">,</span>
45    <span class="identifier">ReadHandler</span><span class="special">&amp;&amp;</span> <span class="identifier">handler</span> <span class="special">=</span> <span class="identifier">net</span><span class="special">::</span><span class="identifier">default_completion_token_t</span><span class="special">&lt;</span> <a class="link" href="executor_type.html" title="websocket::stream::executor_type">executor_type</a> <span class="special">&gt;{});</span>
46</pre>
47<h6>
48<a name="beast.ref.boost__beast__websocket__stream.async_read.h1"></a>
49          <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.async_read.description"></a></span><a class="link" href="async_read.html#beast.ref.boost__beast__websocket__stream.async_read.description">Description</a>
50        </h6>
51<p>
52          This function is used to asynchronously read a complete message. This call
53          always returns immediately. The asynchronous operation will continue until
54          one of the following conditions is true:
55        </p>
56<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
57<li class="listitem">
58              A complete message is received.
59            </li>
60<li class="listitem">
61              A close frame is received. In this case the error indicated by the
62              function will be <a class="link" href="../boost__beast__websocket__error.html" title="websocket::error"><code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">closed</span></code></a>.
63            </li>
64<li class="listitem">
65              An error occurs.
66            </li>
67</ul></div>
68<p>
69          The algorithm, known as a <span class="emphasis"><em>composed asynchronous operation</em></span>,
70          is implemented in terms of calls to the next layer's <code class="computeroutput"><span class="identifier">async_read_some</span></code>
71          and <code class="computeroutput"><span class="identifier">async_write_some</span></code> functions.
72          The program must ensure that no other calls to <a class="link" href="read/overload1.html" title="websocket::stream::read (1 of 2 overloads)"><code class="computeroutput"><span class="identifier">read</span></code></a>, <a class="link" href="read_some/overload1.html" title="websocket::stream::read_some (1 of 4 overloads)"><code class="computeroutput"><span class="identifier">read_some</span></code></a>, <a class="link" href="async_read.html" title="websocket::stream::async_read"><code class="computeroutput"><span class="identifier">async_read</span></code></a>, or <a class="link" href="async_read_some/overload1.html" title="websocket::stream::async_read_some (1 of 2 overloads)"><code class="computeroutput"><span class="identifier">async_read_some</span></code></a> are performed
73          until this operation completes. Received message data is appended to the
74          buffer. The functions <a class="link" href="got_binary.html" title="websocket::stream::got_binary"><code class="computeroutput"><span class="identifier">got_binary</span></code></a> and <a class="link" href="got_text.html" title="websocket::stream::got_text"><code class="computeroutput"><span class="identifier">got_text</span></code></a> may be used to query
75          the stream and determine the type of the last received message. Until the
76          operation completes, the implementation will read incoming control frames
77          and handle them automatically as follows:
78        </p>
79<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
80<li class="listitem">
81              The <a class="link" href="control_callback/overload1.html" title="websocket::stream::control_callback (1 of 2 overloads)"><code class="computeroutput"><span class="identifier">control_callback</span></code></a> will be invoked
82              for each control frame.
83            </li>
84<li class="listitem">
85              For each received ping frame, a pong frame will be automatically sent.
86            </li>
87<li class="listitem">
88              If a close frame is received, the WebSocket close procedure is performed.
89              In this case, when the function returns, the error <a class="link" href="../boost__beast__websocket__error.html" title="websocket::error"><code class="computeroutput"><span class="identifier">error</span><span class="special">::</span><span class="identifier">closed</span></code></a> will be indicated.
90            </li>
91</ul></div>
92<p>
93          Pong frames and close frames sent by the implementation while the read
94          operation is outstanding do not prevent the application from also writing
95          message data, sending pings, sending pongs, or sending close frames.
96        </p>
97<h6>
98<a name="beast.ref.boost__beast__websocket__stream.async_read.h2"></a>
99          <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.async_read.parameters"></a></span><a class="link" href="async_read.html#beast.ref.boost__beast__websocket__stream.async_read.parameters">Parameters</a>
100        </h6>
101<div class="informaltable"><table class="table">
102<colgroup>
103<col>
104<col>
105</colgroup>
106<thead><tr>
107<th>
108                  <p>
109                    Name
110                  </p>
111                </th>
112<th>
113                  <p>
114                    Description
115                  </p>
116                </th>
117</tr></thead>
118<tbody>
119<tr>
120<td>
121                  <p>
122                    <code class="computeroutput"><span class="identifier">buffer</span></code>
123                  </p>
124                </td>
125<td>
126                  <p>
127                    A dynamic buffer to append message data to.
128                  </p>
129                </td>
130</tr>
131<tr>
132<td>
133                  <p>
134                    <code class="computeroutput"><span class="identifier">handler</span></code>
135                  </p>
136                </td>
137<td>
138                  <p>
139                    The completion handler to invoke when the operation completes.
140                    The implementation takes ownership of the handler by performing
141                    a decay-copy. The equivalent function signature of the handler
142                    must be:
143                  </p>
144<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">void</span> <span class="identifier">handler</span><span class="special">(</span>
145    <span class="identifier">error_code</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">,</span>       <span class="comment">// Result of operation</span>
146    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bytes_written</span>   <span class="comment">// Number of bytes appended to buffer</span>
147<span class="special">);</span>
148</pre>
149                  <p>
150                    Regardless of whether the asynchronous operation completes immediately
151                    or not, the handler will not be invoked from within this function.
152                    Invocation of the handler will be performed in a manner equivalent
153                    to using <code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">post</span></code>.
154                  </p>
155                </td>
156</tr>
157</tbody>
158</table></div>
159</div>
160<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
161<td align="left"></td>
162<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie
163      Falco<p>
164        Distributed under the Boost Software License, Version 1.0. (See accompanying
165        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>)
166      </p>
167</div></td>
168</tr></table>
169<hr>
170<div class="spirit-nav">
171<a accesskey="p" href="read/overload2.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost__beast__websocket__stream.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="read_some.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
172</div>
173</body>
174</html>
175