oasys::TokenBucket Class Reference

#include <TokenBucket.h>

Inheritance diagram for oasys::TokenBucket:

oasys::Logger

List of all members.


Detailed Description

A basic token bucket implementation.

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_

Constructor & Destructor Documentation

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_.


Member Function Documentation

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.

Returns:
true if the bucket was drained the given amount, false if there's not enough tokens in the bucket

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 (  ) 

Return the amount of time (in millseconds) until the bucket will be full again.

Definition at line 92 of file TokenBucket.cc.

References depth_, log_debug, rate_, tokens_, and update().

u_int32_t oasys::TokenBucket::depth (  )  const [inline]

Accessors.

Definition at line 62 of file TokenBucket.h.

References depth_.

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]

Setters.

Definition at line 68 of file TokenBucket.h.

References depth_, and update().

void oasys::TokenBucket::set_rate ( u_int32_t  rate  )  [inline]

Setters.

Definition at line 69 of file TokenBucket.h.

References rate_, and update().

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_.


Member Data Documentation

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]

Definition at line 81 of file TokenBucket.h.

Referenced by empty(), TokenBucket(), and update().


The documentation for this class was generated from the following files:
Generated on Sat Sep 8 08:43:56 2007 for DTN Reference Implementation by  doxygen 1.5.3