diff --git a/BasiliskII/src/Unix/configure.ac b/BasiliskII/src/Unix/configure.ac index 9fe4ab17..e0fd2e40 100644 --- a/BasiliskII/src/Unix/configure.ac +++ b/BasiliskII/src/Unix/configure.ac @@ -280,9 +280,13 @@ dnl Checks for header files. 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(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(linux/if.h linux/if_tun.h net/if.h net/if_tun.h, [], [], [ +#ifdef HAVE_SYS_TYPES_H +#include +#endif #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -332,7 +336,7 @@ AC_CHECK_FUNCS(clock_gettime timer_create) AC_CHECK_FUNCS(sigaction signal) AC_CHECK_FUNCS(mmap mprotect munmap) 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(). AC_CHECK_FUNCS(mach_task_self task_self) diff --git a/BasiliskII/src/Unix/ether_unix.cpp b/BasiliskII/src/Unix/ether_unix.cpp index 09a3b461..0c3a94af 100644 --- a/BasiliskII/src/Unix/ether_unix.cpp +++ b/BasiliskII/src/Unix/ether_unix.cpp @@ -20,8 +20,10 @@ #include "sysdeps.h" -#include +#ifdef HAVE_SYS_POLL_H #include +#endif +#include #include #include #include @@ -31,7 +33,7 @@ #include #include -#if defined(__FreeBSD__) || defined(sgi) +#if defined(__FreeBSD__) || defined(sgi) || (defined(__APPLE__) && defined(__MACH__)) #include #endif @@ -98,6 +100,7 @@ static map net_protocols; // Prototypes static void *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 +/* + * 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 */ @@ -567,8 +588,7 @@ static void *receive_func(void *arg) for (;;) { // Wait for packets to arrive - struct pollfd pf = {fd, POLLIN, 0}; - int res = poll(&pf, 1, -1); + int res = poll_fd(fd); if (res <= 0) break;