1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>websocket::stream::read (1 of 2 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="../../../../index.html" title="Chapter 1. Boost.Beast"> 8<link rel="up" href="../read.html" title="websocket::stream::read"> 9<link rel="prev" href="../read.html" title="websocket::stream::read"> 10<link rel="next" href="overload2.html" title="websocket::stream::read (2 of 2 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.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../read.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="overload2.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h6 class="title"> 27<a name="beast.ref.boost__beast__websocket__stream.read.overload1"></a><a class="link" href="overload1.html" title="websocket::stream::read (1 of 2 overloads)">websocket::stream::read 28 (1 of 2 overloads)</a> 29</h6></div></div></div> 30<p> 31 Read a complete message. 32 </p> 33<h7><a name="beast.ref.boost__beast__websocket__stream.read.overload1.h0"></a> 34 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.read.overload1.synopsis"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.read.overload1.synopsis">Synopsis</a> 35 </h7><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> 36 <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> 37<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> 38<span class="identifier">read</span><span class="special">(</span> 39 <span class="identifier">DynamicBuffer</span><span class="special">&</span> <span class="identifier">buffer</span><span class="special">);</span> 40</pre> 41<h7><a name="beast.ref.boost__beast__websocket__stream.read.overload1.h1"></a> 42 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.read.overload1.description"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.read.overload1.description">Description</a> 43 </h7><p> 44 This function is used to read a complete message. The call blocks until 45 one of the following is true: 46 </p> 47<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 48<li class="listitem"> 49 A complete message is received. 50 </li> 51<li class="listitem"> 52 A close frame is received. In this case the error indicated by the 53 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>. 54 </li> 55<li class="listitem"> 56 An error occurs. 57 </li> 58</ul></div> 59<p> 60 The algorithm, known as a <span class="emphasis"><em>composed operation</em></span>, is 61 implemented in terms of calls to the next layer's <code class="computeroutput"><span class="identifier">read_some</span></code> 62 and <code class="computeroutput"><span class="identifier">write_some</span></code> functions. 63 Received message data is appended to the 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 64 the stream and determine the type of the last received message. Until 65 the call returns, the implementation will read incoming control frames 66 and handle them automatically as follows: 67 </p> 68<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 69<li class="listitem"> 70 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 71 invoked for each control frame. 72 </li> 73<li class="listitem"> 74 For each received ping frame, a pong frame will be automatically 75 sent. 76 </li> 77<li class="listitem"> 78 If a close frame is received, the WebSocket closing handshake is 79 performed. 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. 80 </li> 81</ul></div> 82<h7><a name="beast.ref.boost__beast__websocket__stream.read.overload1.h2"></a> 83 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.read.overload1.return_value"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.read.overload1.return_value">Return 84 Value</a> 85 </h7><p> 86 The number of message payload bytes appended to the buffer. 87 </p> 88<h7><a name="beast.ref.boost__beast__websocket__stream.read.overload1.h3"></a> 89 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.read.overload1.parameters"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.read.overload1.parameters">Parameters</a> 90 </h7><div class="informaltable"><table class="table"> 91<colgroup> 92<col> 93<col> 94</colgroup> 95<thead><tr> 96<th> 97 <p> 98 Name 99 </p> 100 </th> 101<th> 102 <p> 103 Description 104 </p> 105 </th> 106</tr></thead> 107<tbody><tr> 108<td> 109 <p> 110 <code class="computeroutput"><span class="identifier">buffer</span></code> 111 </p> 112 </td> 113<td> 114 <p> 115 A dynamic buffer to append message data to. 116 </p> 117 </td> 118</tr></tbody> 119</table></div> 120<h7><a name="beast.ref.boost__beast__websocket__stream.read.overload1.h4"></a> 121 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.read.overload1.exceptions"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.read.overload1.exceptions">Exceptions</a> 122 </h7><div class="informaltable"><table class="table"> 123<colgroup> 124<col> 125<col> 126</colgroup> 127<thead><tr> 128<th> 129 <p> 130 Type 131 </p> 132 </th> 133<th> 134 <p> 135 Thrown On 136 </p> 137 </th> 138</tr></thead> 139<tbody><tr> 140<td> 141 <p> 142 <code class="computeroutput"><span class="identifier">system_error</span></code> 143 </p> 144 </td> 145<td> 146 <p> 147 Thrown on failure. 148 </p> 149 </td> 150</tr></tbody> 151</table></div> 152</div> 153<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 154<td align="left"></td> 155<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie 156 Falco<p> 157 Distributed under the Boost Software License, Version 1.0. (See accompanying 158 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 </p> 160</div></td> 161</tr></table> 162<hr> 163<div class="spirit-nav"> 164<a accesskey="p" href="../read.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../read.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="overload2.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 165</div> 166</body> 167</html> 168