[BUG] fix null timeouts in *poll-based pollers

Introduction of timeval timers broke *poll-based pollers, because the call to
tv_ms_remain may return 0 while the event is not elapsed yet. Now we carefully
check for those cases and round the result up by 1 ms.
This commit is contained in:
Willy Tarreau 2007-05-14 02:02:04 +02:00
parent aff694f3b6
commit bdefc513a0
3 changed files with 15 additions and 9 deletions

View File

@ -231,10 +231,12 @@ REGPRM2 static void _do_poll(struct poller *p, struct timeval *exp)
fd_flush_changes();
/* now let's wait for events */
if (tv_isset(exp))
wait_time = tv_ms_remain(&now, exp);
else
if (tv_iseternity(exp))
wait_time = -1;
else if (tv_isge(&now, exp))
wait_time = 0;
else
wait_time = __tv_ms_elapsed(&now, exp) + 1;
status = epoll_wait(epoll_fd, epoll_events, maxfd, wait_time);
tv_now(&now);

View File

@ -124,10 +124,12 @@ REGPRM2 static void _do_poll(struct poller *p, struct timeval *exp)
}
/* now let's wait for events */
if (tv_isset(exp))
wait_time = tv_ms_remain(&now, exp);
else
if (tv_iseternity(exp))
wait_time = -1;
else if (tv_isge(&now, exp))
wait_time = 0;
else
wait_time = __tv_ms_elapsed(&now, exp) + 1;
status = poll(poll_events, nbfd, wait_time);
tv_now(&now);

View File

@ -380,10 +380,12 @@ REGPRM2 static void _do_poll(struct poller *p, struct timeval *exp)
wait_time = 0;
}
else {
if (tv_isset(exp))
wait_time = tv_ms_remain(&now, exp);
else
if (tv_iseternity(exp))
wait_time = -1;
else if (tv_isge(&now, exp))
wait_time = 0;
else
wait_time = __tv_ms_elapsed(&now, exp) + 1;
}
/* now let's wait for real events */