From: Cedric Cellier Date: Sat, 15 Oct 2011 14:25:21 +0000 (+0200) Subject: Default to using poll(2) in `fport_input_waiting'. X-Git-Url: https://git.hcoop.net/bpt/guile.git/commitdiff_plain/c7519da3eaef6cf6d862a87e2d050766eb6c4388 Default to using poll(2) in `fport_input_waiting'. * libguile/fports.c (fport_input_waiting): Use poll(2) instead of select(2) when possible. Cosmetic changes by Ludovic Courtès. --- 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;