|
swift
|
Token bucket algorithm. More...
Public Member Functions | |
| CTokenBucket (int capacity, qint64 intervalMs, int numTokensToRefill) | |
| Constructor for given replenishment policy. | |
| bool | tryConsume (int numTokens=1, qint64 msSinceEpoch=-1) |
| Try to consume a number of tokens. More... | |
| void | setNumberOfTokensToRefill (int numTokens) |
| Number of tokens to refill. | |
| void | setCapacity (int capacity) |
| Set the capacity. | |
| void | setCapacityAndTokensToRefill (int numTokens) |
| Tokens/capacity if both are same. | |
| void | setInterval (qint64 intervalMs) |
| Set the interval. | |
| int | getTokensPerSecond () const |
| Tokens per second. | |
Token bucket algorithm.
This class implements the token bucket algorithm. Tokens as arbitrary unit are added to the bucket at a defined rate. Token can be consumsed as long as there are enough available. This class can be used to throttle traffic and packet generation. Each time a packet needs to be generated and sent a token is consumed. If no token is available, consumption will fail the the packet cannot be sent.
Definition at line 20 of file tokenbucket.h.
| bool swift::misc::CTokenBucket::tryConsume | ( | int | numTokens = 1, |
| qint64 | msSinceEpoch = -1 |
||
| ) |
Try to consume a number of tokens.
Definition at line 14 of file tokenbucket.cpp.