ratecheck(9)

ratecheck9

Event rate limiting

Usage

#include <sys/time.h>

int

ratecheck(struct timeval *lasttime, const struct timeval *mininterval);

int

ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps);

Overview

The ratecheck and ppsratecheck functions facilitate rate-limiting of arbitrary events. The former enforces a minimum interval between events while the latter enforces a maximum number of events per second.

The ratecheck function compares the current time to the value pointed to by lasttime. If the difference is equal to or greater than mininterval, it returns a non-zero value and updates lasttime to the current time. Otherwise, it returns zero.

The ppsratecheck function first compares the current time to lasttime. If at least a full second has passed, the value pointed to by the curpps argument is reset to 1 and lasttime is updated to the current time. Otherwise, curpps is incremented and lasttime is left untouched. In either case, ppsratecheck returns a non-zero value if and only if the updated curpps is less than or equal to maxpps or maxpps is negative.

Releases

20 releases since FreeBSD 12.0-RELEASE; the text changed 7 times.

  1. 12.0
  2. 12.1
  3. 12.2
  4. 12.3
  5. 12.4
  6. 13.0–13.2
  7. 13.3–13.5
  8. 14.0–16.0

History

The ratecheck and ppsratecheck functions first appeared in FreeBSD 5.1.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.