1[/ 2 Copyright (c) 2019 Vinnie Falco (vinnie dot falco at gmail dot com) 3 4 Distributed under the Boost Software License, Version 1.0. (See accompanying 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 Official repository: https://github.com/boostorg/beast 8] 9 10[section:RatePolicy RatePolicy] 11 12An instance of [*RatePolicy] is associated with a 13[link beast.ref.boost__beast__basic_stream `basic_stream`], 14and controls the rate at which bytes may be independently sent and 15received. This may be used to achieve fine-grained bandwidth management 16and flow control. 17 18[heading Associated Types] 19 20* [link beast.ref.boost__beast__rate_policy_access `rate_policy_access`] 21 22[warning 23 These requirements may undergo non-backward compatible 24 changes in subsequent versions. 25] 26 27[heading Requirements] 28 29In this table: 30 31* `P` denotes a type that meets the requirements of [*RatePolicy]. 32* `x` denotes an xvalue of type `P` 33* `a` denotes a value of type `P`. 34* `n` denotes a value of type `std::size_t` 35 36[table Valid expressions 37[[Expression] [Type] [Semantics, Pre/Post-conditions]] 38[ 39 [`P a(x)`] 40 [] 41 [ 42 Requires ['MoveConstructible]. 43 ] 44][ 45 [`friend rate_policy_access`] 46 [] 47 [ 48 The member functions required in `P` should be private. 49 [link beast.ref.boost__beast__rate_policy_access `rate_policy_access`] 50 must be a friend of `P` for the implementation to gain access 51 to the required member functions. 52 ] 53][ 54 [`a.available_read_bytes()`] 55 [`std::size_t`] 56 [ 57 This function is called by the implementation to determine 58 the maximum number of allowed bytes to be transferred 59 in the next read operation. The actual number of bytes 60 subsequently transferred may be less than this number. 61 62 If the policy returns a value of zero, the read operation 63 will asynchronously wait until the next timer interval 64 before retrying. When the retry occurs, this function will 65 be called again. 66 ] 67][ 68 [`a.available_write_bytes()`] 69 [`std::size_t`] 70 [ 71 This function is called by the implementation to determine 72 the maximum number of allowed bytes to be transferred 73 in the next write operation. The actual number of bytes 74 subsequently transferred may be less than this number. 75 76 If the policy returns a value of zero, the read operation 77 will asynchronously wait until the next timer interval 78 before retrying. When the retry occurs, this function will 79 be called again. 80 ] 81][ 82 [`a.transfer_read_bytes(n)`] 83 [] 84 [ 85 The implementation calls this function to inform the 86 policy that `n` bytes were successfully transferred 87 in the most recent read operation. The policy object 88 may optionally use this information to calculate 89 throughputs and/or inform the algorithm used to 90 determine subsequently queried transfer maximums. 91 ] 92][ 93 [`a.transfer_write_bytes(n)`] 94 [] 95 [ 96 The implementation calls this function to inform the 97 policy that `n` bytes were successfully transferred 98 in the most recent write operation. The policy object 99 may optionally use this information to calculate 100 throughputs and/or inform the algorithm used to 101 determine subsequently queried transfer limits. 102 ] 103][ 104 [`a.on_timer()`] 105 [] 106 [ 107 The implementation calls this function every time the 108 internal timer expires. The policy object may optionally 109 use this opportunity to calculate elapsed time and 110 throughput, and/or inform the algorithm used to 111 determine subsequently queried transfer limits. 112 ] 113]] 114 115[heading Exemplar] 116 117[concept_RatePolicy] 118 119[heading Models] 120 121* [link beast.ref.boost__beast__simple_rate_policy `simple_rate_policy`] 122* [link beast.ref.boost__beast__unlimited_rate_policy `unlimited_rate_policy`] 123 124[endsect] 125