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

@ -142,9 +142,8 @@ select_del(struct event *ev, int flags)
}
static int
select_process(u_long msec)
select_process(struct timeval *tv)
{
struct timeval tv, *tp;
struct event *ev;
int ready, i;
@ -155,14 +154,10 @@ select_process(u_long msec)
max_fd = events[i]->fd;
}
tv.tv_sec = (long) (msec / 1000);
tv.tv_usec = (long) ((msec % 1000) * 1000);
tp = &tv;
work_read_fd_set = master_read_fd_set;
work_write_fd_set = master_write_fd_set;
ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tp);
ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tv);
if (ready == -1) {
if (errno == EINTR)