mirror of https://github.com/getdnsapi/getdns.git
Merge pull request #276 from huitema/develop
Fixing the select and poll event loops for Windows
This commit is contained in:
commit
148dfabf88
|
@ -30,8 +30,10 @@
|
||||||
#ifdef HAVE_SYS_POLL_H
|
#ifdef HAVE_SYS_POLL_H
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#else
|
#else
|
||||||
|
#ifndef USE_WINSOCK
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -402,6 +404,10 @@ poll_eventloop_run_once(getdns_eventloop *loop, int blocking)
|
||||||
, poll_timeout
|
, poll_timeout
|
||||||
);
|
);
|
||||||
#ifdef USE_WINSOCK
|
#ifdef USE_WINSOCK
|
||||||
|
if (poll_loop->fd_events_free == 0)
|
||||||
|
{
|
||||||
|
Sleep(poll_timeout);
|
||||||
|
} else
|
||||||
if (WSAPoll(poll_loop->pfds, poll_loop->fd_events_free, poll_timeout) < 0) {
|
if (WSAPoll(poll_loop->pfds, poll_loop->fd_events_free, poll_timeout) < 0) {
|
||||||
#else
|
#else
|
||||||
if (poll(poll_loop->pfds, poll_loop->fd_events_free, poll_timeout) < 0) {
|
if (poll(poll_loop->pfds, poll_loop->fd_events_free, poll_timeout) < 0) {
|
||||||
|
|
|
@ -234,6 +234,16 @@ select_eventloop_run_once(getdns_eventloop *loop, int blocking)
|
||||||
tv.tv_sec = (long)((timeout - now) / 1000000);
|
tv.tv_sec = (long)((timeout - now) / 1000000);
|
||||||
tv.tv_usec = (long)((timeout - now) % 1000000);
|
tv.tv_usec = (long)((timeout - now) % 1000000);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_WINSOCK
|
||||||
|
if (max_fd == -1)
|
||||||
|
{
|
||||||
|
if (timeout != TIMEOUT_FOREVER)
|
||||||
|
{
|
||||||
|
uint32_t timeout_ms = (tv.tv_usec / 1000) + (tv.tv_sec * 1000);
|
||||||
|
Sleep(timeout_ms);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
if (select(max_fd + 1, &readfds, &writefds, NULL,
|
if (select(max_fd + 1, &readfds, &writefds, NULL,
|
||||||
(timeout == TIMEOUT_FOREVER ? NULL : &tv)) < 0) {
|
(timeout == TIMEOUT_FOREVER ? NULL : &tv)) < 0) {
|
||||||
perror("select() failed");
|
perror("select() failed");
|
||||||
|
|
|
@ -36,7 +36,11 @@
|
||||||
# ifdef HAVE_SYS_POLL_H
|
# ifdef HAVE_SYS_POLL_H
|
||||||
# include <sys/poll.h>
|
# include <sys/poll.h>
|
||||||
# else
|
# else
|
||||||
|
#ifdef USE_WINSOCK
|
||||||
|
#define poll(fdarray, nbsockets, timer) WSAPoll(fdarray, nbsockets, timer)
|
||||||
|
#else
|
||||||
# include <poll.h>
|
# include <poll.h>
|
||||||
|
#endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
Loading…
Reference in New Issue