1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>RatePolicy</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="../concepts.html" title="Concepts"> 9<link rel="prev" href="File.html" title="File"> 10<link rel="next" href="streams.html" title="Streams"> 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="File.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.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="streams.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="beast.concepts.RatePolicy"></a><a class="link" href="RatePolicy.html" title="RatePolicy">RatePolicy</a> 28</h3></div></div></div> 29<p> 30 An instance of <span class="bold"><strong>RatePolicy</strong></span> is associated 31 with a <a class="link" href="../ref/boost__beast__basic_stream.html" title="basic_stream"><code class="computeroutput"><span class="identifier">basic_stream</span></code></a>, and controls the rate 32 at which bytes may be independently sent and received. This may be used to 33 achieve fine-grained bandwidth management and flow control. 34 </p> 35<h5> 36<a name="beast.concepts.RatePolicy.h0"></a> 37 <span class="phrase"><a name="beast.concepts.RatePolicy.associated_types"></a></span><a class="link" href="RatePolicy.html#beast.concepts.RatePolicy.associated_types">Associated 38 Types</a> 39 </h5> 40<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 41 <a class="link" href="../ref/boost__beast__rate_policy_access.html" title="rate_policy_access"><code class="computeroutput"><span class="identifier">rate_policy_access</span></code></a> 42 </li></ul></div> 43<div class="warning"><table border="0" summary="Warning"> 44<tr> 45<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../doc/src/images/warning.png"></td> 46<th align="left">Warning</th> 47</tr> 48<tr><td align="left" valign="top"><p> 49 These requirements may undergo non-backward compatible changes in subsequent 50 versions. 51 </p></td></tr> 52</table></div> 53<h5> 54<a name="beast.concepts.RatePolicy.h1"></a> 55 <span class="phrase"><a name="beast.concepts.RatePolicy.requirements"></a></span><a class="link" href="RatePolicy.html#beast.concepts.RatePolicy.requirements">Requirements</a> 56 </h5> 57<p> 58 In this table: 59 </p> 60<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 61<li class="listitem"> 62 <code class="computeroutput"><span class="identifier">P</span></code> denotes a type that 63 meets the requirements of <span class="bold"><strong>RatePolicy</strong></span>. 64 </li> 65<li class="listitem"> 66 <code class="computeroutput"><span class="identifier">x</span></code> denotes an xvalue of 67 type <code class="computeroutput"><span class="identifier">P</span></code> 68 </li> 69<li class="listitem"> 70 <code class="computeroutput"><span class="identifier">a</span></code> denotes a value of 71 type <code class="computeroutput"><span class="identifier">P</span></code>. 72 </li> 73<li class="listitem"> 74 <code class="computeroutput"><span class="identifier">n</span></code> denotes a value of 75 type <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span></code> 76 </li> 77</ul></div> 78<div class="table"> 79<a name="beast.concepts.RatePolicy.valid_expressions"></a><p class="title"><b>Table 1.44. Valid expressions</b></p> 80<div class="table-contents"><table class="table" summary="Valid expressions"> 81<colgroup> 82<col> 83<col> 84<col> 85</colgroup> 86<thead><tr> 87<th> 88 <p> 89 Expression 90 </p> 91 </th> 92<th> 93 <p> 94 Type 95 </p> 96 </th> 97<th> 98 <p> 99 Semantics, Pre/Post-conditions 100 </p> 101 </th> 102</tr></thead> 103<tbody> 104<tr> 105<td> 106 <p> 107 <code class="computeroutput"><span class="identifier">P</span> <span class="identifier">a</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code> 108 </p> 109 </td> 110<td> 111 </td> 112<td> 113 <p> 114 Requires <span class="emphasis"><em>MoveConstructible</em></span>. 115 </p> 116 </td> 117</tr> 118<tr> 119<td> 120 <p> 121 <code class="computeroutput"><span class="keyword">friend</span> <span class="identifier">rate_policy_access</span></code> 122 </p> 123 </td> 124<td> 125 </td> 126<td> 127 <p> 128 The member functions required in <code class="computeroutput"><span class="identifier">P</span></code> 129 should be private. <a class="link" href="../ref/boost__beast__rate_policy_access.html" title="rate_policy_access"><code class="computeroutput"><span class="identifier">rate_policy_access</span></code></a> must 130 be a friend of <code class="computeroutput"><span class="identifier">P</span></code> 131 for the implementation to gain access to the required member functions. 132 </p> 133 </td> 134</tr> 135<tr> 136<td> 137 <p> 138 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">available_read_bytes</span><span class="special">()</span></code> 139 </p> 140 </td> 141<td> 142 <p> 143 <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span></code> 144 </p> 145 </td> 146<td> 147 <p> 148 This function is called by the implementation to determine the 149 maximum number of allowed bytes to be transferred in the next read 150 operation. The actual number of bytes subsequently transferred 151 may be less than this number. 152 </p> 153 <p> 154 If the policy returns a value of zero, the read operation will 155 asynchronously wait until the next timer interval before retrying. 156 When the retry occurs, this function will be called again. 157 </p> 158 </td> 159</tr> 160<tr> 161<td> 162 <p> 163 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">available_write_bytes</span><span class="special">()</span></code> 164 </p> 165 </td> 166<td> 167 <p> 168 <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span></code> 169 </p> 170 </td> 171<td> 172 <p> 173 This function is called by the implementation to determine the 174 maximum number of allowed bytes to be transferred in the next write 175 operation. The actual number of bytes subsequently transferred 176 may be less than this number. 177 </p> 178 <p> 179 If the policy returns a value of zero, the read operation will 180 asynchronously wait until the next timer interval before retrying. 181 When the retry occurs, this function will be called again. 182 </p> 183 </td> 184</tr> 185<tr> 186<td> 187 <p> 188 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">transfer_read_bytes</span><span class="special">(</span><span class="identifier">n</span><span class="special">)</span></code> 189 </p> 190 </td> 191<td> 192 </td> 193<td> 194 <p> 195 The implementation calls this function to inform the policy that 196 <code class="computeroutput"><span class="identifier">n</span></code> bytes were successfully 197 transferred in the most recent read operation. The policy object 198 may optionally use this information to calculate throughputs and/or 199 inform the algorithm used to determine subsequently queried transfer 200 maximums. 201 </p> 202 </td> 203</tr> 204<tr> 205<td> 206 <p> 207 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">transfer_write_bytes</span><span class="special">(</span><span class="identifier">n</span><span class="special">)</span></code> 208 </p> 209 </td> 210<td> 211 </td> 212<td> 213 <p> 214 The implementation calls this function to inform the policy that 215 <code class="computeroutput"><span class="identifier">n</span></code> bytes were successfully 216 transferred in the most recent write operation. The policy object 217 may optionally use this information to calculate throughputs and/or 218 inform the algorithm used to determine subsequently queried transfer 219 limits. 220 </p> 221 </td> 222</tr> 223<tr> 224<td> 225 <p> 226 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">on_timer</span><span class="special">()</span></code> 227 </p> 228 </td> 229<td> 230 </td> 231<td> 232 <p> 233 The implementation calls this function every time the internal 234 timer expires. The policy object may optionally use this opportunity 235 to calculate elapsed time and throughput, and/or inform the algorithm 236 used to determine subsequently queried transfer limits. 237 </p> 238 </td> 239</tr> 240</tbody> 241</table></div> 242</div> 243<br class="table-break"><h5> 244<a name="beast.concepts.RatePolicy.h2"></a> 245 <span class="phrase"><a name="beast.concepts.RatePolicy.exemplar"></a></span><a class="link" href="RatePolicy.html#beast.concepts.RatePolicy.exemplar">Exemplar</a> 246 </h5> 247<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">RatePolicy</span> 248<span class="special">{</span> 249 <span class="keyword">friend</span> <span class="keyword">class</span> <span class="identifier">rate_policy_access</span><span class="special">;</span> 250 251 <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> 252 <span class="identifier">available_read_bytes</span><span class="special">();</span> 253 254 <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> 255 <span class="identifier">available_write_bytes</span><span class="special">();</span> 256 257 <span class="keyword">void</span> 258 <span class="identifier">transfer_read_bytes</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">);</span> 259 260 <span class="keyword">void</span> 261 <span class="identifier">transfer_write_bytes</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">);</span> 262 263 <span class="keyword">void</span> 264 <span class="identifier">on_timer</span><span class="special">();</span> 265<span class="special">};</span> 266</pre> 267<h5> 268<a name="beast.concepts.RatePolicy.h3"></a> 269 <span class="phrase"><a name="beast.concepts.RatePolicy.models"></a></span><a class="link" href="RatePolicy.html#beast.concepts.RatePolicy.models">Models</a> 270 </h5> 271<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 272<li class="listitem"> 273 <a class="link" href="../ref/boost__beast__simple_rate_policy.html" title="simple_rate_policy"><code class="computeroutput"><span class="identifier">simple_rate_policy</span></code></a> 274 </li> 275<li class="listitem"> 276 <a class="link" href="../ref/boost__beast__unlimited_rate_policy.html" title="unlimited_rate_policy"><code class="computeroutput"><span class="identifier">unlimited_rate_policy</span></code></a> 277 </li> 278</ul></div> 279</div> 280<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 281<td align="left"></td> 282<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie 283 Falco<p> 284 Distributed under the Boost Software License, Version 1.0. (See accompanying 285 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>) 286 </p> 287</div></td> 288</tr></table> 289<hr> 290<div class="spirit-nav"> 291<a accesskey="p" href="File.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.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="streams.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 292</div> 293</body> 294</html> 295