Use timevals everywhere where it is possible, including API between main

loop and event dispatchers. This simplifies code and eliminates a bug,
when kevent dispatcher is called with 0 timeout.

While here, in the main loop call gettimeofday() right after event
dispatcher returns. Otherwise, we are using outdated "timeofday" in
second part of the loop. I don't know any bugs because of that, but
they are possible.
This commit is contained in:
Gleb Smirnoff
2019-05-08 14:19:46 -07:00
parent cad8c922f0
commit 1d363c209f
4 changed files with 31 additions and 47 deletions

View File

@@ -178,27 +178,21 @@ kqueue_set(struct event *ev, short filter, u_short flags, u_int fflags)
}
static int
kqueue_process(u_long timer)
kqueue_process(struct timeval *tv)
{
struct event *ev;
int events, n, i;
struct timespec ts, *tp;
struct timespec ts;
n = (int) nchanges;
nchanges = 0;
if (timer == 0) {
tp = NULL;
} else {
ts.tv_sec = timer / 1000;
ts.tv_nsec = (timer % 1000) * 1000000;
tp = &ts;
}
TIMEVAL_TO_TIMESPEC(tv, &ts);
DPRINTF(E_DEBUG, L_GENERAL, "kevent timer: %lu, changes: %d\n",
timer, n);
DPRINTF(E_DEBUG, L_GENERAL, "kevent timer: %lu.%06lu, changes: %d\n",
ts.tv_sec, ts.tv_nsec, n);
events = kevent(kq, change_list, n, event_list, MAXEVENTS, tp);
events = kevent(kq, change_list, n, event_list, MAXEVENTS, &ts);
if (events == -1) {
if (errno == EINTR)
@@ -208,12 +202,6 @@ kqueue_process(u_long timer)
DPRINTF(E_DEBUG, L_GENERAL, "kevent events: %d\n", events);
if (events == 0) {
if (timer != 0)
return (0);
DPRINTF(E_FATAL, L_GENERAL, "kevent() returned no events. EXITING\n");
}
for (i = 0; i < events; i++) {
if (event_list[i].flags & EV_ERROR) {
DPRINTF(E_ERROR, L_GENERAL,