#include <TokenBucket.h>
Inheritance diagram for oasys::TokenBucket:
Definition at line 28 of file TokenBucket.h.
Public Member Functions | |
TokenBucket (const char *logpath, u_int32_t depth, u_int32_t rate) | |
Constructor that takes the initial depth and rate parameters. | |
bool | drain (u_int32_t length) |
Try to drain the specified amount from the bucket. | |
void | update () |
Update the number of tokens in the bucket without draining any. | |
u_int32_t | time_to_fill () |
Return the amount of time (in millseconds) until the bucket will be full again. | |
void | empty () |
Empty the bucket. | |
u_int32_t | depth () const |
Accessors. | |
u_int32_t | rate () const |
Accessors. | |
u_int32_t | tokens () const |
Accessors. | |
void | set_depth (u_int32_t depth) |
Setters. | |
void | set_rate (u_int32_t rate) |
Setters. | |
Protected Attributes | |
u_int32_t | depth_ |
u_int32_t | rate_ |
u_int32_t | tokens_ |
Time | last_update_ |
oasys::TokenBucket::TokenBucket | ( | const char * | logpath, | |
u_int32_t | depth, | |||
u_int32_t | rate | |||
) |
Constructor that takes the initial depth and rate parameters.
Definition at line 23 of file TokenBucket.cc.
References depth_, oasys::Time::get_time(), last_update_, log_debug, and rate_.
bool oasys::TokenBucket::drain | ( | u_int32_t | length | ) |
Try to drain the specified amount from the bucket.
Note that this function will first try to fill() the bucket, so in fact, this is the only function (besides the constructor) that needs to be called in order for the bucket to work properly.
Definition at line 74 of file TokenBucket.cc.
References log_debug, tokens_, and update().
Referenced by oasys::RateLimitedSocket::send(), and oasys::RateLimitedSocket::sendto().
void oasys::TokenBucket::update | ( | ) |
Update the number of tokens in the bucket without draining any.
Since drain() will also update the number of tokens, there's usually no reason to call this function explicitly.
Definition at line 38 of file TokenBucket.cc.
References depth_, oasys::Time::get_time(), last_update_, log_debug, rate_, and tokens_.
Referenced by drain(), set_depth(), set_rate(), and time_to_fill().
u_int32_t oasys::TokenBucket::time_to_fill | ( | ) |
u_int32_t oasys::TokenBucket::depth | ( | ) | const [inline] |
u_int32_t oasys::TokenBucket::rate | ( | ) | const [inline] |
Accessors.
Definition at line 63 of file TokenBucket.h.
References rate_.
Referenced by oasys::RateLimitedSocket::send(), and oasys::RateLimitedSocket::sendto().
u_int32_t oasys::TokenBucket::tokens | ( | ) | const [inline] |
Accessors.
Definition at line 64 of file TokenBucket.h.
References tokens_.
Referenced by oasys::RateLimitedSocket::send(), and oasys::RateLimitedSocket::sendto().
void oasys::TokenBucket::set_depth | ( | u_int32_t | depth | ) | [inline] |
void oasys::TokenBucket::set_rate | ( | u_int32_t | rate | ) | [inline] |
void oasys::TokenBucket::empty | ( | ) |
Empty the bucket.
Definition at line 105 of file TokenBucket.cc.
References oasys::Time::get_time(), last_update_, log_debug, and tokens_.
u_int32_t oasys::TokenBucket::depth_ [protected] |
Definition at line 78 of file TokenBucket.h.
Referenced by depth(), set_depth(), time_to_fill(), TokenBucket(), and update().
u_int32_t oasys::TokenBucket::rate_ [protected] |
Definition at line 79 of file TokenBucket.h.
Referenced by rate(), set_rate(), time_to_fill(), TokenBucket(), and update().
u_int32_t oasys::TokenBucket::tokens_ [protected] |
Definition at line 80 of file TokenBucket.h.
Referenced by drain(), empty(), time_to_fill(), tokens(), and update().
Time oasys::TokenBucket::last_update_ [protected] |