Marine Library
1.0
C++ library for Linux Networking Development
|
Rate limiting for any frequency, including ones less than 1Hz. More...
#include <freq_control.hh>
Public Member Functions | |
bool | get () |
Get 1 token. More... | |
CWideFreqControl (double freq=0) | |
Initialize this object. More... | |
void | init (double freq) |
Initialize this object. More... | |
Rate limiting for any frequency, including ones less than 1Hz.
For any given frequency F:
F >= 1
, CWideFreqControl generates F
tokens per second; 0 < F < 1
, CWideFreqControl generate 1 token in every 1/F
seconds; Although CWideFreqControl is more powerful than CFreqControl, it has a simpler interface. After initialization, you can only get 1 token a time, and don't need to generate any more, because it has been done in get. And there is no way to check or overdraw tokens, because that might indicate a bad design of logic oftentimes.
CWideFreqControl has a fixed bucket size of (F + 1)
.
All these considerations make CWideFreqControl simple and efficient enough for real world projects even with float-point operations.
|
inlineexplicit |
Initialize this object.
freq | A non-negative real number denoting frequency |
|
inline |
Get 1 token.
true:
Succeeded. One token is removed from bucket; false:
Failed. No token is removed.
|
inline |
Initialize this object.
freq | A non-negative real number denoting frequency |