Data Fields
ratelim_t Struct Reference

#include <ratelim.h>

Data Fields

int rate
time_t last_allowed
int n_calls_since_last_time

Detailed Description

A ratelim_t remembers how often an event is occurring, and how often it's allowed to occur. Typical usage is something like:

 if (possibly_very_frequent_event()) {
   const int INTERVAL = 300;
   static ratelim_t warning_limit = RATELIM_INIT(INTERVAL);
   char *m;
   if ((m = rate_limit_log(&warning_limit, approx_time()))) {
     log_warn(LD_GENERAL, "The event occurred!%s", m);

As a convenience wrapper for logging, you can replace the above with:

if (possibly_very_frequent_event()) {
  static ratelim_t warning_limit = RATELIM_INIT(300);
  log_fn_ratelim(&warning_limit, LOG_WARN, LD_GENERAL,
                 "The event occurred!");

Definition at line 42 of file ratelim.h.

The documentation for this struct was generated from the following file: