2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2010-01-29 04:42:57 +01:00
|
|
|
|
2015-11-30 21:43:37 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "time-util.h"
|
2010-01-29 04:42:57 +01:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
typedef struct RateLimit {
|
2019-09-19 17:41:20 +02:00
|
|
|
usec_t interval; /* Keep those two fields first so they can be initialized easily: */
|
|
|
|
unsigned burst; /* RateLimit rl = { INTERVAL, BURST }; */
|
2011-02-21 15:32:18 +01:00
|
|
|
unsigned num;
|
2019-09-19 17:41:20 +02:00
|
|
|
usec_t begin;
|
2010-01-29 04:42:57 +01:00
|
|
|
} RateLimit;
|
|
|
|
|
2019-09-19 17:41:20 +02:00
|
|
|
static inline void ratelimit_reset(RateLimit *rl) {
|
|
|
|
rl->num = rl->begin = 0;
|
|
|
|
}
|
2012-07-04 00:23:42 +02:00
|
|
|
|
2018-05-11 11:16:52 +02:00
|
|
|
bool ratelimit_below(RateLimit *r);
|