X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=ucw%2Ftbf.c;h=62b0c41cd51f49a66c7289405f8d1ede7b2da6a7;hb=b8667492cf36a609939ee35ac42900ff0b0cc80f;hp=7e4d474ef82793e4a9fdb08c78f3e6c792b0ad3c;hpb=16f04029db50b765d952cf4cf053d34262a40db1;p=libucw.git diff --git a/ucw/tbf.c b/ucw/tbf.c index 7e4d474e..62b0c41c 100644 --- a/ucw/tbf.c +++ b/ucw/tbf.c @@ -7,8 +7,8 @@ * of the GNU Lesser General Public License. */ -#include "ucw/lib.h" -#include "ucw/tbf.h" +#include +#include void tbf_init(struct token_bucket_filter *f) @@ -29,13 +29,16 @@ tbf_limit(struct token_bucket_filter *f, timestamp_t now) b = MIN(b, f->burst); if (b >= 1) { + uint dropped = f->drop_count; f->bucket = b - 1; - return 1; + f->drop_count = 0; + return dropped; } else { f->bucket = b; - return 0; + f->drop_count++; + return -f->drop_count; } } @@ -48,7 +51,7 @@ int main(void) for (timestamp_t now = 0; now < 3000; now += 77) { int res = tbf_limit(&t, now); - msg(L_DEBUG, "t=%u result=%d bucket=%f", (uns) now, res, t.bucket); + msg(L_DEBUG, "t=%u result=%d bucket=%f", (uint) now, res, t.bucket); } return 0; }