aboutsummaryrefslogtreecommitdiffstats
path: root/leaky-bucket.h
blob: 18bd02dc7897639cf926cd03940156ea7d9d0435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef LEAKY_BUCKET_H
#define LEAKY_BUCKET_H 1

#include <time.h>
#include <stdbool.h>

/* Leaky bucket algorithm for triggers */

struct bucket_conf {
	unsigned capacity;
	unsigned agetime;
	unsigned char tunit;	/* 'd','h','m','s' */
	unsigned char log;
	char *trigger;
};

struct leaky_bucket {
	unsigned count;
	unsigned excess;
	time_t   tstamp;
};

int bucket_account(const struct bucket_conf *c, struct leaky_bucket *b, 
		   unsigned inc);
int __bucket_account(const struct bucket_conf *c, struct leaky_bucket *b, 
		   unsigned inc, time_t time);
char *bucket_output(const struct bucket_conf *c, struct leaky_bucket *b);
int bucket_conf_init(struct bucket_conf *c, const char *rate);
void bucket_init(struct leaky_bucket *b);
time_t bucket_time(void);
void bucket_age(const struct bucket_conf *c, struct leaky_bucket *b,
			time_t now);

#endif