1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>websocket::stream::control_callback (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="../control_callback.html" title="websocket::stream::control_callback"> 9<link rel="prev" href="../control_callback.html" title="websocket::stream::control_callback"> 10<link rel="next" href="overload2.html" title="websocket::stream::control_callback (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="../control_callback.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../control_callback.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.control_callback.overload1"></a><a class="link" href="overload1.html" title="websocket::stream::control_callback (1 of 2 overloads)">websocket::stream::control_callback 28 (1 of 2 overloads)</a> 29</h6></div></div></div> 30<p> 31 Set a callback to be invoked on each incoming control frame. 32 </p> 33<h7><a name="beast.ref.boost__beast__websocket__stream.control_callback.overload1.h0"></a> 34 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.control_callback.overload1.synopsis"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.control_callback.overload1.synopsis">Synopsis</a> 35 </h7><pre class="programlisting"><span class="keyword">void</span> 36<span class="identifier">control_callback</span><span class="special">(</span> 37 <span class="identifier">std</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="keyword">void</span><span class="special">(</span><span class="identifier">frame_type</span><span class="special">,</span> <span class="identifier">string_view</span><span class="special">)></span> <span class="identifier">cb</span><span class="special">);</span> 38</pre> 39<h7><a name="beast.ref.boost__beast__websocket__stream.control_callback.overload1.h1"></a> 40 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.control_callback.overload1.description"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.control_callback.overload1.description">Description</a> 41 </h7><p> 42 Sets the callback to be invoked whenever a ping, pong, or close control 43 frame is received during a call to one of the following functions: 44 </p> 45<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 46<li class="listitem"> 47 <a class="link" href="../read/overload1.html" title="websocket::stream::read (1 of 2 overloads)"><code class="computeroutput"><span class="identifier">beast</span><span class="special">::</span><span class="identifier">websocket</span><span class="special">::</span><span class="identifier">stream</span><span class="special">::</span><span class="identifier">read</span></code></a> 48 </li> 49<li class="listitem"> 50 <a class="link" href="../read_some/overload1.html" title="websocket::stream::read_some (1 of 4 overloads)"><code class="computeroutput"><span class="identifier">beast</span><span class="special">::</span><span class="identifier">websocket</span><span class="special">::</span><span class="identifier">stream</span><span class="special">::</span><span class="identifier">read_some</span></code></a> 51 </li> 52<li class="listitem"> 53 <a class="link" href="../async_read.html" title="websocket::stream::async_read"><code class="computeroutput"><span class="identifier">beast</span><span class="special">::</span><span class="identifier">websocket</span><span class="special">::</span><span class="identifier">stream</span><span class="special">::</span><span class="identifier">async_read</span></code></a> 54 </li> 55<li class="listitem"> 56 <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">beast</span><span class="special">::</span><span class="identifier">websocket</span><span class="special">::</span><span class="identifier">stream</span><span class="special">::</span><span class="identifier">async_read_some</span></code></a> 57 </li> 58</ul></div> 59<p> 60 Unlike completion handlers, the callback will be invoked for each control 61 frame during a call to any synchronous or asynchronous read function. 62 The operation is passive, with no associated error code, and triggered 63 by reads. For close frames, the close reason code may be obtained by 64 calling the function <a class="link" href="../reason.html" title="websocket::stream::reason"><code class="computeroutput"><span class="identifier">reason</span></code></a>. 65 </p> 66<h7><a name="beast.ref.boost__beast__websocket__stream.control_callback.overload1.h2"></a> 67 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.control_callback.overload1.parameters"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.control_callback.overload1.parameters">Parameters</a> 68 </h7><div class="informaltable"><table class="table"> 69<colgroup> 70<col> 71<col> 72</colgroup> 73<thead><tr> 74<th> 75 <p> 76 Name 77 </p> 78 </th> 79<th> 80 <p> 81 Description 82 </p> 83 </th> 84</tr></thead> 85<tbody><tr> 86<td> 87 <p> 88 <code class="computeroutput"><span class="identifier">cb</span></code> 89 </p> 90 </td> 91<td> 92 <p> 93 The function object to call, which must be invocable with this 94 equivalent signature: 95 </p> 96<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">void</span> 97<span class="identifier">callback</span><span class="special">(</span> 98 <span class="identifier">frame_type</span> <span class="identifier">kind</span><span class="special">,</span> <span class="comment">// The type of frame</span> 99 <span class="identifier">string_view</span> <span class="identifier">payload</span> <span class="comment">// The payload in the frame</span> 100<span class="special">);</span> 101</pre> 102 <p> 103 The implementation type-erases the callback which may require 104 a dynamic allocation. To prevent the possibility of a dynamic 105 allocation, use <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ref</span></code> 106 to wrap the callback. If the read operation which receives 107 the control frame is an asynchronous operation, the callback 108 will be invoked using the same method as that used to invoke 109 the final handler. 110 </p> 111 </td> 112</tr></tbody> 113</table></div> 114<h7><a name="beast.ref.boost__beast__websocket__stream.control_callback.overload1.h3"></a> 115 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.control_callback.overload1.remarks"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.control_callback.overload1.remarks">Remarks</a> 116 </h7><p> 117 Incoming ping and close frames are automatically handled. Pings are responded 118 to with pongs, and a close frame is responded to with a close frame leading 119 to the closure of the stream. It is not necessary to manually send pings, 120 pongs, or close frames from inside the control callback. Attempting to 121 manually send a close frame from inside the control callback after receiving 122 a close frame will result in undefined behavior. 123 </p> 124</div> 125<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 126<td align="left"></td> 127<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie 128 Falco<p> 129 Distributed under the Boost Software License, Version 1.0. (See accompanying 130 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>) 131 </p> 132</div></td> 133</tr></table> 134<hr> 135<div class="spirit-nav"> 136<a accesskey="p" href="../control_callback.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../control_callback.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> 137</div> 138</body> 139</html> 140