From c7519da3eaef6cf6d862a87e2d050766eb6c4388 Mon Sep 17 00:00:00 2001 From: Cedric Cellier Date: Sat, 15 Oct 2011 16:25:21 +0200 Subject: [PATCH] Default to using poll(2) in `fport_input_waiting'. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * libguile/fports.c (fport_input_waiting): Use poll(2) instead of select(2) when possible. Cosmetic changes by Ludovic Courtès. --- libguile/fports.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libguile/fports.c b/libguile/fports.c index 0b84d4413..1348b8b5c 100644 --- a/libguile/fports.c +++ b/libguile/fports.c @@ -49,7 +49,9 @@ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE #include #endif - +#ifdef HAVE_POLL_H +#include +#endif #include #include @@ -585,8 +587,21 @@ scm_fdes_to_port (int fdes, char *mode, SCM name) static int fport_input_waiting (SCM port) { -#ifdef HAVE_SELECT int fdes = SCM_FSTREAM (port)->fdes; + + /* `FD_SETSIZE', which is 1024 on GNU systems, effectively limits the + highest numerical value of file descriptors that can be monitored. + Thus, use poll(2) whenever that is possible. */ + +#ifdef HAVE_POLL + struct pollfd pollfd = { fdes, POLLIN, 0 }; + + if (poll (&pollfd, 1, 0) < 0) + scm_syserror ("fport_input_waiting"); + + return pollfd.revents & POLLIN ? 1 : 0; + +#elif defined(HAVE_SELECT) struct timeval timeout; SELECT_TYPE read_set; SELECT_TYPE write_set;