]> mj.ucw.cz Git - libucw.git/blob - ucw/tbf.h
Logging: Introduce LS_NUM_TYPES and use it.
[libucw.git] / ucw / tbf.h
1 /*
2  *      UCW Library -- Rate Limiting based on the Token Bucket Filter
3  *
4  *      (c) 2009 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UCW_TBF_H_
11 #define _UCW_TBF_H_
12
13 struct token_bucket_filter {
14   double rate;                          // Number of tokens per second
15   uns burst;                            // Capacity of the bucket
16   timestamp_t last_hit;                 // Internal state...
17   double bucket;
18 };
19
20 void tbf_init(struct token_bucket_filter *f);
21 int tbf_limit(struct token_bucket_filter *f, timestamp_t now);
22
23 #endif