* ratecheck(): simple time-based rate-limit checking. */
| 1023 | * ratecheck(): simple time-based rate-limit checking. |
| 1024 | */ |
| 1025 | int |
| 1026 | ratecheck(struct timeval *lasttime, const struct timeval *mininterval) |
| 1027 | { |
| 1028 | struct timeval tv, delta; |
| 1029 | int rv = 0; |
| 1030 | |
| 1031 | getmicrouptime(&tv); /* NB: 10ms precision */ |
| 1032 | delta = tv; |
| 1033 | timevalsub(&delta, lasttime); |
| 1034 | |
| 1035 | /* |
| 1036 | * check for 0,0 is so that the message will be seen at least once, |
| 1037 | * even if interval is huge. |
| 1038 | */ |
| 1039 | if (timevalcmp(&delta, mininterval, >=) || |
| 1040 | (lasttime->tv_sec == 0 && lasttime->tv_usec == 0)) { |
| 1041 | *lasttime = tv; |
| 1042 | rv = 1; |
| 1043 | } |
| 1044 | |
| 1045 | return (rv); |
| 1046 | } |
| 1047 | |
| 1048 | /* |
| 1049 | * ppsratecheck(): packets (or events) per second limitation. |
no test coverage detected