From 2a155c53abb729788c1299fffb166a1aeb30fdd9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 8 Oct 2020 18:40:35 +0200 Subject: [PATCH] ratelimit: add ratelimit_configured() helper This helper alone doesn't make too much sense, but it's preparatory work for #17274, and I guess it can't hurt to land it early, it does make the ratelimit code a tiny bit prettier after all. --- src/basic/ratelimit.c | 2 +- src/basic/ratelimit.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/basic/ratelimit.c b/src/basic/ratelimit.c index 4e04e04426..2e94eed843 100644 --- a/src/basic/ratelimit.c +++ b/src/basic/ratelimit.c @@ -13,7 +13,7 @@ bool ratelimit_below(RateLimit *r) { assert(r); - if (r->interval <= 0 || r->burst <= 0) + if (!ratelimit_configured(r)) return true; ts = now(CLOCK_MONOTONIC); diff --git a/src/basic/ratelimit.h b/src/basic/ratelimit.h index 79e33b6a62..9d409b04b3 100644 --- a/src/basic/ratelimit.h +++ b/src/basic/ratelimit.h @@ -17,4 +17,8 @@ static inline void ratelimit_reset(RateLimit *rl) { rl->num = rl->begin = 0; } +static inline bool ratelimit_configured(RateLimit *rl) { + return rl->interval > 0 && rl->burst > 0; +} + bool ratelimit_below(RateLimit *r);