summaryrefslogtreecommitdiff
path: root/epoll.c
diff options
context:
space:
mode:
authorChristopher Davis <chrisd@mangrin.org>2010-03-31 20:30:55 -0700
committerChristopher Davis <chrisd@mangrin.org>2010-03-31 23:38:34 -0700
commit850c3ff232659125262bb5e30bef8451fac386bf (patch)
tree70a0b33e9d67c6fc3c939fadefc85dc645d341ca /epoll.c
parentc87272b7b91b4f443092eb2a81f03c83457ab03a (diff)
downloadlibevent-850c3ff232659125262bb5e30bef8451fac386bf.tar.gz
Add evutil_tv_to_msec for safe conversion of timevals to milliseconds.
This is useful for backends that require their timeout values be in milliseconds.
Diffstat (limited to 'epoll.c')
-rw-r--r--epoll.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/epoll.c b/epoll.c
index 53c1f09a..6c3cf33f 100644
--- a/epoll.c
+++ b/epoll.c
@@ -35,6 +35,7 @@
#include <sys/queue.h>
#include <sys/epoll.h>
#include <signal.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -269,15 +270,16 @@ epoll_dispatch(struct event_base *base, struct timeval *tv)
{
struct epollop *epollop = base->evbase;
struct epoll_event *events = epollop->events;
- int i, res, timeout = -1;
-
- if (tv != NULL)
- timeout = tv->tv_sec * 1000 + (tv->tv_usec + 999) / 1000;
-
- if (timeout > MAX_EPOLL_TIMEOUT_MSEC) {
- /* Linux kernels can wait forever if the timeout is too big;
- * see comment on MAX_EPOLL_TIMEOUT_MSEC. */
- timeout = MAX_EPOLL_TIMEOUT_MSEC;
+ int i, res;
+ long timeout = -1;
+
+ if (tv != NULL) {
+ timeout = evutil_tv_to_msec(tv);
+ if (timeout < 0 || timeout > MAX_EPOLL_TIMEOUT_MSEC) {
+ /* Linux kernels can wait forever if the timeout is
+ * too big; see comment on MAX_EPOLL_TIMEOUT_MSEC. */
+ timeout = MAX_EPOLL_TIMEOUT_MSEC;
+ }
}
epoll_apply_changes(base);