From c27411f180c42c89e1282edf0c992b6d11c8db7f 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. * configure.in: Look for and `poll'. --- configure.in | 7 ++++--- libguile/fports.c | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/configure.in b/configure.in index 217ac83e3..4ce2783a6 100644 --- a/configure.in +++ b/configure.in @@ -4,7 +4,8 @@ dnl define(GUILE_CONFIGURE_COPYRIGHT,[[ -Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, + 2006, 2007, 2008, 2009, 2011 Free Software Foundation, Inc. This file is part of GUILE @@ -661,7 +662,7 @@ AC_CHECK_HEADERS([complex.h fenv.h io.h libc.h limits.h malloc.h memory.h proces regex.h rxposix.h rx/rxposix.h sys/dir.h sys/ioctl.h sys/select.h \ sys/time.h sys/timeb.h sys/times.h sys/stdtypes.h sys/types.h \ sys/utime.h time.h unistd.h utime.h pwd.h grp.h sys/utsname.h \ -direct.h strings.h machine/fpu.h]) +direct.h strings.h machine/fpu.h poll.h]) # "complex double" is new in C99, and "complex" is only a keyword if # is included @@ -755,7 +756,7 @@ AC_CHECK_HEADERS([assert.h crt_externs.h]) # isblank - available as a GNU extension or in C99 # _NSGetEnviron - Darwin specific # -AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid fesetround ftime ftruncate fchown getcwd geteuid gettimeofday gmtime_r ioctl lstat mkdir mknod nice pipe _pipe readdir_r readdir64_r readlink rename rmdir select setegid seteuid setlocale setpgid setsid sigaction siginterrupt stat64 strftime strptime symlink sync sysconf tcgetpgrp tcsetpgrp times uname waitpid strdup system usleep atexit on_exit chown link fcntl ttyname getpwent getgrent kill getppid getpgrp fork setitimer getitimer strchr strcmp index bcopy memcpy rindex truncate unsetenv isblank _NSGetEnviron strncasecmp]) +AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid fesetround ftime ftruncate fchown getcwd geteuid gettimeofday gmtime_r ioctl lstat mkdir mknod nice pipe _pipe readdir_r readdir64_r readlink rename rmdir select setegid seteuid setlocale setpgid setsid sigaction siginterrupt stat64 strftime strptime symlink sync sysconf tcgetpgrp tcsetpgrp times uname waitpid strdup system usleep atexit on_exit chown link fcntl ttyname getpwent getgrent kill getppid getpgrp fork setitimer getitimer strchr strcmp index bcopy memcpy rindex truncate unsetenv isblank _NSGetEnviron strncasecmp poll]) # Reasons for testing: # netdb.h - not in mingw diff --git a/libguile/fports.c b/libguile/fports.c index 007ee3f93..e7ad4a30d 100644 --- a/libguile/fports.c +++ b/libguile/fports.c @@ -46,7 +46,9 @@ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE #include #endif - +#ifdef HAVE_POLL_H +#include +#endif #include #include @@ -485,8 +487,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;