Use a custom poll_fd() function implemented as select() on platforms that

don't support poll() natively, e.g. MacOS X and some older BSDs.
This commit is contained in:
gbeauche 2005-05-13 17:43:38 +00:00
parent d9839e7079
commit 63015fd6d3
2 changed files with 30 additions and 6 deletions

View File

@ -280,9 +280,13 @@ dnl Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h fcntl.h sys/types.h sys/time.h sys/mman.h mach/mach.h) AC_CHECK_HEADERS(unistd.h fcntl.h sys/types.h sys/time.h sys/mman.h mach/mach.h)
AC_CHECK_HEADERS(readline.h history.h readline/readline.h readline/history.h) AC_CHECK_HEADERS(readline.h history.h readline/readline.h readline/history.h)
AC_CHECK_HEADERS(sys/socket.h sys/ioctl.h sys/filio.h sys/bitypes.h sys/wait.h sys/select.h) AC_CHECK_HEADERS(sys/socket.h sys/ioctl.h sys/filio.h sys/bitypes.h sys/wait.h)
AC_CHECK_HEADERS(sys/poll.h sys/select.h)
AC_CHECK_HEADERS(arpa/inet.h) AC_CHECK_HEADERS(arpa/inet.h)
AC_CHECK_HEADERS(linux/if.h linux/if_tun.h net/if.h net/if_tun.h, [], [], [ AC_CHECK_HEADERS(linux/if.h linux/if_tun.h net/if.h net/if_tun.h, [], [], [
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H #ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h> #include <sys/socket.h>
#endif #endif
@ -332,7 +336,7 @@ AC_CHECK_FUNCS(clock_gettime timer_create)
AC_CHECK_FUNCS(sigaction signal) AC_CHECK_FUNCS(sigaction signal)
AC_CHECK_FUNCS(mmap mprotect munmap) AC_CHECK_FUNCS(mmap mprotect munmap)
AC_CHECK_FUNCS(vm_allocate vm_deallocate vm_protect) AC_CHECK_FUNCS(vm_allocate vm_deallocate vm_protect)
AC_CHECK_FUNCS(inet_aton) AC_CHECK_FUNCS(poll inet_aton)
dnl Darwin seems to define mach_task_self() instead of task_self(). dnl Darwin seems to define mach_task_self() instead of task_self().
AC_CHECK_FUNCS(mach_task_self task_self) AC_CHECK_FUNCS(mach_task_self task_self)

View File

@ -20,8 +20,10 @@
#include "sysdeps.h" #include "sysdeps.h"
#include <sys/ioctl.h> #ifdef HAVE_SYS_POLL_H
#include <sys/poll.h> #include <sys/poll.h>
#endif
#include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -31,7 +33,7 @@
#include <stdio.h> #include <stdio.h>
#include <map> #include <map>
#if defined(__FreeBSD__) || defined(sgi) #if defined(__FreeBSD__) || defined(sgi) || (defined(__APPLE__) && defined(__MACH__))
#include <net/if.h> #include <net/if.h>
#endif #endif
@ -98,6 +100,7 @@ static map<uint16, uint32> net_protocols;
// Prototypes // Prototypes
static void *receive_func(void *arg); static void *receive_func(void *arg);
static void *slirp_receive_func(void *arg); static void *slirp_receive_func(void *arg);
static int poll_fd(int fd);
/* /*
@ -558,6 +561,24 @@ void slirp_output(const uint8 *packet, int len)
#endif #endif
/*
* Wait for data to arrive
*/
static inline int poll_fd(int fd)
{
#ifdef HAVE_POLL
struct pollfd pf = {fd, POLLIN, 0};
return poll(&pf, 1, -1);
#else
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
return select(1, &rfds, NULL, NULL, NULL);
#endif
}
/* /*
* Packet reception thread * Packet reception thread
*/ */
@ -567,8 +588,7 @@ static void *receive_func(void *arg)
for (;;) { for (;;) {
// Wait for packets to arrive // Wait for packets to arrive
struct pollfd pf = {fd, POLLIN, 0}; int res = poll_fd(fd);
int res = poll(&pf, 1, -1);
if (res <= 0) if (res <= 0)
break; break;