#include <sys/queue.h>
#include <sys/epoll.h>
#include <signal.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
{
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);
#include <stdlib.h>
#endif
#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <string.h>
#ifdef _EVENT_HAVE_ARPA_INET_H
return 0;
}
+#define MAX_SECONDS_IN_MSEC_LONG \
+ (((LONG_MAX) - 999) / 1000)
+
+long
+evutil_tv_to_msec(const struct timeval *tv)
+{
+ if (tv->tv_usec > 1000000 || tv->tv_sec > MAX_SECONDS_IN_MSEC_LONG)
+ return -1;
+
+ return (tv->tv_sec * 1000) + (tv->tv_usec / 1000);
+}
+
#include <sys/queue.h>
#include <poll.h>
#include <signal.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
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);
* ::1). */
int evutil_sockaddr_is_loopback(const struct sockaddr *sa);
+long evutil_tv_to_msec(const struct timeval *tv);
+
#ifdef __cplusplus
}
#endif
#include <windows.h>
#include <sys/types.h>
#include <sys/queue.h>
+#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
return (0);
}
-static int
-timeval_to_ms(struct timeval *tv)
-{
- return ((tv->tv_sec * 1000) + (tv->tv_usec / 1000));
-}
-
static int
do_fd_set(struct win32op *op, struct idx_info *ent, evutil_socket_t s, int read)
{
win32op->readset_out->fd_count : win32op->writeset_out->fd_count;
if (!fd_count) {
+ long msec = evutil_tv_to_msec(tv);
+ /* Sleep's DWORD argument is unsigned long */
+ if (msec < 0)
+ msec = LONG_MAX;
/* Windows doesn't like you to call select() with no sockets */
- Sleep(timeval_to_ms(tv));
+ Sleep(msec);
evsig_process(base);
return (0);
}