The
ratecheck() function provides a simple time interval check which can be used when implementing time-based rate-limited actions. If the difference between the current monotonically-increasing system time (
mono_time) and
lasttime is less than the value given by the
mininterval argument, zero is returned. Otherwise,
lasttime is set to the current time and a non-zero value is returned.
The motivation for implementing
ratecheck() was to provide a mechanism that could be used to add rate limiting to diagnostic message output. If printed too often, diagnostic messages can keep the system from doing useful work. If the repeated messages can be caused by deliberate user action or network events, they can be exploited to cause denial of system service.
Note that using a very short time interval (less than a second) for
mininterval defeats the purpose of this function. (It doesn't take much to flood a 9600 baud serial console with output, for instance.)