From 24eea1be08391475fe932f44df51ebe1aca75a2b Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Wed, 1 Mar 2017 17:25:59 +0100 Subject: [PATCH] "select" no longer throws exception on EINTR * doc/ref/posix.texi (Ports and File Descriptors): Update. * libguile/filesys.c (scm_select): Use scm_std_select so that pending interrupts can be delivered. On EINTR or EAGAIN, just return directly so that calling Scheme code can run asyncs. --- doc/ref/posix.texi | 8 ++++---- libguile/filesys.c | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi index 4afe6bf20..6f9ce545e 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -529,10 +529,10 @@ to provide input, accept output, or the existence of exceptional conditions on a collection of ports or file descriptors, or waiting for a timeout to occur. -When an error occurs, of if it is interrupted by a signal, this -procedure throws a @code{system-error} exception -(@pxref{Conventions, @code{system-error}}). In case of an -interruption, the associated error number is @var{EINTR}. +When an error occurs, this procedure throws a @code{system-error} +exception (@pxref{Conventions, @code{system-error}}). Note that +@code{select} may return early for other reasons, for example due to +pending interrupts. @xref{Asyncs}, for more on interrupts. @var{reads}, @var{writes} and @var{excepts} can be lists or vectors, with each member a port or a file descriptor. diff --git a/libguile/filesys.c b/libguile/filesys.c index b5b7e723b..478369df0 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -44,6 +44,7 @@ #include "libguile/feature.h" #include "libguile/fports.h" #include "libguile/strings.h" +#include "libguile/iselect.h" #include "libguile/vectors.h" #include "libguile/dynwind.h" #include "libguile/ports.h" @@ -79,8 +80,6 @@ #include #endif -#include - #ifdef HAVE_STRING_H #include #endif @@ -776,10 +775,9 @@ SCM_DEFINE (scm_select, "select", 3, 2, 0, "exceptional conditions on a collection of ports or file\n" "descriptors, or waiting for a timeout to occur.\n\n" - "When an error occurs, of if it is interrupted by a signal, this\n" - "procedure throws a @code{system-error} exception\n" - "(@pxref{Conventions, @code{system-error}}). In case of an\n" - "interruption, the associated error number is @var{EINTR}.\n\n" + "When an error occurs, this procedure throws a\n" + "@code{system-error} exception " + "(@pxref{Conventions, @code{system-error}}).\n\n" "@var{reads}, @var{writes} and @var{excepts} can be lists or\n" "vectors, with each member a port or a file descriptor.\n" @@ -899,12 +897,15 @@ SCM_DEFINE (scm_select, "select", 3, 2, 0, } { - int rv = select (max_fd + 1, - &read_set, &write_set, &except_set, - time_ptr); - if (rv < 0) + int rv = scm_std_select (max_fd + 1, + &read_set, &write_set, &except_set, + time_ptr); + /* Let EINTR / EAGAIN cause a return to the user and let them loop + to run any asyncs that might be pending. */ + if (rv < 0 && errno != EINTR && errno != EAGAIN) SCM_SYSERROR; } + return scm_list_3 (retrieve_select_type (&read_set, read_ports_ready, reads), retrieve_select_type (&write_set, write_ports_ready, writes), retrieve_select_type (&except_set, SCM_EOL, excepts));