summaryrefslogtreecommitdiff
path: root/poll.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 /poll.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 'poll.c')
-rw-r--r--poll.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/poll.c b/poll.c
index 84e7944e..abbf90eb 100644
--- a/poll.c
+++ b/poll.c
@@ -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);