mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-13 06:16:10 -04:00
Merge branch 'safetimevalms'
This commit is contained in:
commit
fd90274056
18
epoll.c
18
epoll.c
@ -35,6 +35,7 @@
|
|||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -269,15 +270,16 @@ epoll_dispatch(struct event_base *base, struct timeval *tv)
|
|||||||
{
|
{
|
||||||
struct epollop *epollop = base->evbase;
|
struct epollop *epollop = base->evbase;
|
||||||
struct epoll_event *events = epollop->events;
|
struct epoll_event *events = epollop->events;
|
||||||
int i, res, timeout = -1;
|
int i, res;
|
||||||
|
long timeout = -1;
|
||||||
|
|
||||||
if (tv != NULL)
|
if (tv != NULL) {
|
||||||
timeout = tv->tv_sec * 1000 + (tv->tv_usec + 999) / 1000;
|
timeout = evutil_tv_to_msec(tv);
|
||||||
|
if (timeout < 0 || timeout > MAX_EPOLL_TIMEOUT_MSEC) {
|
||||||
if (timeout > MAX_EPOLL_TIMEOUT_MSEC) {
|
/* Linux kernels can wait forever if the timeout is
|
||||||
/* Linux kernels can wait forever if the timeout is too big;
|
* too big; see comment on MAX_EPOLL_TIMEOUT_MSEC. */
|
||||||
* see comment on MAX_EPOLL_TIMEOUT_MSEC. */
|
timeout = MAX_EPOLL_TIMEOUT_MSEC;
|
||||||
timeout = MAX_EPOLL_TIMEOUT_MSEC;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
epoll_apply_changes(base);
|
epoll_apply_changes(base);
|
||||||
|
13
evutil.c
13
evutil.c
@ -52,6 +52,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef _EVENT_HAVE_ARPA_INET_H
|
#ifdef _EVENT_HAVE_ARPA_INET_H
|
||||||
@ -1894,3 +1895,15 @@ evutil_sockaddr_is_loopback(const struct sockaddr *addr)
|
|||||||
return 0;
|
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 + 999) / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
11
poll.c
11
poll.c
@ -35,6 +35,7 @@
|
|||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -117,7 +118,8 @@ poll_check_ok(struct pollop *pop)
|
|||||||
static int
|
static int
|
||||||
poll_dispatch(struct event_base *base, struct timeval *tv)
|
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 pollop *pop = base->evbase;
|
||||||
struct pollfd *event_set;
|
struct pollfd *event_set;
|
||||||
|
|
||||||
@ -152,8 +154,11 @@ poll_dispatch(struct event_base *base, struct timeval *tv)
|
|||||||
event_set = pop->event_set;
|
event_set = pop->event_set;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (tv != NULL)
|
if (tv != NULL) {
|
||||||
msec = tv->tv_sec * 1000 + (tv->tv_usec + 999) / 1000;
|
msec = evutil_tv_to_msec(tv);
|
||||||
|
if (msec < 0 || msec > INT_MAX)
|
||||||
|
msec = INT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
EVBASE_RELEASE_LOCK(base, th_base_lock);
|
EVBASE_RELEASE_LOCK(base, th_base_lock);
|
||||||
|
|
||||||
|
@ -213,6 +213,8 @@ int evutil_getaddrinfo_async(struct evdns_base *dns_base,
|
|||||||
* ::1). */
|
* ::1). */
|
||||||
int evutil_sockaddr_is_loopback(const struct sockaddr *sa);
|
int evutil_sockaddr_is_loopback(const struct sockaddr *sa);
|
||||||
|
|
||||||
|
long evutil_tv_to_msec(const struct timeval *tv);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -114,12 +115,6 @@ realloc_fd_sets(struct win32op *op, size_t new_size)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
timeval_to_ms(struct timeval *tv)
|
|
||||||
{
|
|
||||||
return ((tv->tv_sec * 1000) + (tv->tv_usec / 1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
do_fd_set(struct win32op *op, struct idx_info *ent, evutil_socket_t s, int read)
|
do_fd_set(struct win32op *op, struct idx_info *ent, evutil_socket_t s, int read)
|
||||||
{
|
{
|
||||||
@ -303,8 +298,12 @@ win32_dispatch(struct event_base *base, struct timeval *tv)
|
|||||||
win32op->readset_out->fd_count : win32op->writeset_out->fd_count;
|
win32op->readset_out->fd_count : win32op->writeset_out->fd_count;
|
||||||
|
|
||||||
if (!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 */
|
/* Windows doesn't like you to call select() with no sockets */
|
||||||
Sleep(timeval_to_ms(tv));
|
Sleep(msec);
|
||||||
evsig_process(base);
|
evsig_process(base);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user