diff options
author | Christopher Davis <chrisd@mangrin.org> | 2010-03-31 20:30:55 -0700 |
---|---|---|
committer | Christopher Davis <chrisd@mangrin.org> | 2010-03-31 23:38:34 -0700 |
commit | 850c3ff232659125262bb5e30bef8451fac386bf (patch) | |
tree | 70a0b33e9d67c6fc3c939fadefc85dc645d341ca /poll.c | |
parent | c87272b7b91b4f443092eb2a81f03c83457ab03a (diff) | |
download | libevent-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 'poll.c')
-rw-r--r-- | poll.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -35,6 +35,7 @@ #include <sys/queue.h> #include <poll.h> #include <signal.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -117,7 +118,8 @@ poll_check_ok(struct pollop *pop) static int poll_dispatch(struct event_base *base, struct timeval *tv) { - int res, i, j, msec = -1, nfds; + int res, i, j, nfds; + long msec = -1; struct pollop *pop = base->evbase; struct pollfd *event_set; @@ -152,8 +154,11 @@ poll_dispatch(struct event_base *base, struct timeval *tv) event_set = pop->event_set; #endif - if (tv != NULL) - msec = tv->tv_sec * 1000 + (tv->tv_usec + 999) / 1000; + if (tv != NULL) { + msec = evutil_tv_to_msec(tv); + if (msec < 0 || msec > INT_MAX) + msec = INT_MAX; + } EVBASE_RELEASE_LOCK(base, th_base_lock); |