diff options
Diffstat (limited to 'ares_timeout.c')
-rw-r--r-- | ares_timeout.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/ares_timeout.c b/ares_timeout.c index 2da4f5f..0b5a435 100644 --- a/ares_timeout.c +++ b/ares_timeout.c @@ -16,12 +16,10 @@ #include "ares_setup.h" -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +#ifdef HAVE_LIMITS_H +#include <limits.h> #endif -#include <time.h> - #include "ares.h" #include "ares_private.h" @@ -62,19 +60,22 @@ struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv, min_offset = offset; } - if(min_offset != -1) { - nextstop.tv_sec = min_offset/1000; - nextstop.tv_usec = (min_offset%1000)*1000; - } - /* If we found a minimum timeout and it's sooner than the one specified in * maxtv (if any), return it. Otherwise go with maxtv. */ - if (min_offset != -1 && (!maxtv || ares__timedout(maxtv, &nextstop))) + if (min_offset != -1) { - *tvbuf = nextstop; - return tvbuf; + int ioffset = (min_offset > (long)INT_MAX) ? INT_MAX : (int)min_offset; + + nextstop.tv_sec = ioffset/1000; + nextstop.tv_usec = (ioffset%1000)*1000; + + if (!maxtv || ares__timedout(maxtv, &nextstop)) + { + *tvbuf = nextstop; + return tvbuf; + } } - else - return maxtv; + + return maxtv; } |