diff options
author | Gary Houston <ghouston@arglist.com> | 1997-05-15 08:46:37 +0000 |
---|---|---|
committer | Gary Houston <ghouston@arglist.com> | 1997-05-15 08:46:37 +0000 |
commit | a48a89bc1705db11abd626edf41363c03de46f35 (patch) | |
tree | c2804635d09c45816c0f3736d927607f4d26994a | |
parent | 223be5f0438eec153b2aacc8dd3820dab9cf38e0 (diff) | |
download | guile-a48a89bc1705db11abd626edf41363c03de46f35.tar.gz |
* posix.c: don't include <sys/select.h> or define macros for
select, since they were not used in this file.
* * filesys.c (scm_select): make the fifth parameter microseconds,
not milliseconds. let the fourth parameter be either a real value
or an integer or #f. The first, second and third arguments can
now be vectors: the type of the corresponding return set will be
the same.
(set_element, get_element): new static procedures.
-rw-r--r-- | libguile/ChangeLog | 12 | ||||
-rw-r--r-- | libguile/filesys.c | 141 | ||||
-rw-r--r-- | libguile/posix.c | 21 |
3 files changed, 107 insertions, 67 deletions
diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 062178c84..1ddc72c04 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,15 @@ +Thu May 15 05:21:36 1997 Gary Houston <ghouston@actrix.gen.nz> + + * posix.c: don't include <sys/select.h> or define macros for + select, since they were not used in this file. + +* * filesys.c (scm_select): make the fifth parameter microseconds, + not milliseconds. let the fourth parameter be either a real value + or an integer or #f. The first, second and third arguments can + now be vectors: the type of the corresponding return set will be + the same. + (set_element, get_element): new static procedures. + Wed May 14 12:18:12 1997 Jim Blandy <jimb@floss.cyclic.com> * strports.c (scm_eval_string): New function. diff --git a/libguile/filesys.c b/libguile/filesys.c index 750d5a2d3..eaec974fc 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -717,67 +717,97 @@ scm_getcwd () -static void fill_select_type SCM_P ((SELECT_TYPE * set, SCM list)); +static void +set_element (SELECT_TYPE *set, SCM element) +{ + if (SCM_NIMP (element) && SCM_TYP16 (element) == scm_tc16_fport + && SCM_OPPORTP (element)) + FD_SET (fileno ((FILE *) SCM_STREAM (element)), set); + else if (SCM_INUMP (element)) + FD_SET (SCM_INUM (element), set); +} static void -fill_select_type (set, list) - SELECT_TYPE * set; - SCM list; +fill_select_type (SELECT_TYPE *set, SCM list) { - while (list != SCM_EOL) + if (SCM_NIMP (list) && SCM_VECTORP (list)) { - if ( SCM_NIMP (SCM_CAR (list)) - && (scm_tc16_fport == SCM_TYP16 (SCM_CAR (list))) - && SCM_OPPORTP (SCM_CAR (list))) - FD_SET (fileno ((FILE *)SCM_STREAM (SCM_CAR (list))), set); - else if (SCM_INUMP (SCM_CAR (list))) - FD_SET (SCM_INUM (SCM_CAR (list)), set); - list = SCM_CDR (list); + int len = SCM_LENGTH (list); + SCM *ve = SCM_VELTS (list); + + while (len > 0) + { + set_element (set, ve[len - 1]); + len--; + } + } + else + { + while (list != SCM_EOL) + { + set_element (set, SCM_CAR (list)); + list = SCM_CDR (list); + } } } - -static SCM retrieve_select_type SCM_P ((SELECT_TYPE * set, SCM list)); +static SCM +get_element (SELECT_TYPE *set, SCM element, SCM list) +{ + if (SCM_NIMP (element) + && (scm_tc16_fport == SCM_TYP16 (element)) + && SCM_OPPORTP (element)) + { + if (FD_ISSET (fileno ((FILE *)SCM_STREAM (element)), set)) + list = scm_cons (element, list); + } + else if (SCM_INUMP (element)) + { + if (FD_ISSET (SCM_INUM (element), set)) + list = scm_cons (element, list); + } + return list; +} static SCM -retrieve_select_type (set, list) - SELECT_TYPE * set; - SCM list; +retrieve_select_type (SELECT_TYPE *set, SCM list) { - SCM answer; - answer = SCM_EOL; - while (list != SCM_EOL) + SCM answer_list = SCM_EOL; + + if (SCM_NIMP (list) && SCM_VECTORP (list)) { - if ( SCM_NIMP (SCM_CAR (list)) - && (scm_tc16_fport == SCM_TYP16 (SCM_CAR (list))) - && SCM_OPPORTP (SCM_CAR (list))) + int len = SCM_LENGTH (list); + SCM *ve = SCM_VELTS (list); + + while (len > 0) { - if (FD_ISSET (fileno ((FILE *)SCM_STREAM (SCM_CAR (list))), set)) - answer = scm_cons (SCM_CAR (list), answer); + answer_list = get_element (set, ve[len - 1], answer_list); + len--; } - else if (SCM_INUMP (SCM_CAR (list))) + return scm_vector (answer_list); + } + else + { + /* list is a list. */ + while (list != SCM_EOL) { - if (FD_ISSET (SCM_INUM (SCM_CAR (list)), set)) - answer = scm_cons (SCM_CAR (list), answer); + answer_list = get_element (set, SCM_CAR (list), answer_list); + list = SCM_CDR (list); } - list = SCM_CDR (list); + return answer_list; } - return answer; } -/* {Checking for events} - */ - SCM_PROC (s_select, "select", 3, 2, 0, scm_select); SCM -scm_select (reads, writes, excepts, secs, msecs) +scm_select (reads, writes, excepts, secs, usecs) SCM reads; SCM writes; SCM excepts; SCM secs; - SCM msecs; + SCM usecs; { #ifdef HAVE_SELECT struct timeval timeout; @@ -787,9 +817,13 @@ scm_select (reads, writes, excepts, secs, msecs) SELECT_TYPE except_set; int sreturn; - SCM_ASSERT (-1 < scm_ilength (reads), reads, SCM_ARG1, s_select); - SCM_ASSERT (-1 < scm_ilength (writes), reads, SCM_ARG1, s_select); - SCM_ASSERT (-1 < scm_ilength (excepts), reads, SCM_ARG1, s_select); +#define assert_set(x, arg) \ + SCM_ASSERT (scm_ilength (x) > -1 || (SCM_NIMP (x) && SCM_VECTORP (x)), \ + x, arg, s_select) + assert_set (reads, SCM_ARG1); + assert_set (writes, SCM_ARG2); + assert_set (excepts, SCM_ARG3); +#undef assert_set FD_ZERO (&read_set); FD_ZERO (&write_set); @@ -799,18 +833,33 @@ scm_select (reads, writes, excepts, secs, msecs) fill_select_type (&write_set, writes); fill_select_type (&except_set, excepts); - if (SCM_UNBNDP (secs)) + if (SCM_UNBNDP (secs) || SCM_FALSEP (secs)) time_p = 0; else { - SCM_ASSERT (SCM_INUMP (secs), secs, SCM_ARG4, s_select); - if (SCM_UNBNDP (msecs)) - msecs = SCM_INUM0; + if (SCM_INUMP (secs)) + { + timeout.tv_sec = SCM_INUM (secs); + if (SCM_UNBNDP (usecs)) + timeout.tv_usec = 0; + else + { + SCM_ASSERT (SCM_INUMP (usecs), usecs, SCM_ARG5, s_select); + + timeout.tv_usec = SCM_INUM (usecs); + } + } else - SCM_ASSERT (SCM_INUMP (msecs), msecs, SCM_ARG5, s_select); - - timeout.tv_sec = SCM_INUM (secs); - timeout.tv_usec = 1000 * SCM_INUM (msecs); + { + double fl = scm_num2dbl (secs, s_select); + + if (!SCM_UNBNDP (usecs)) + scm_wrong_type_arg (s_select, 4, secs); + if (fl > LONG_MAX) + scm_out_of_range (s_select, secs); + timeout.tv_sec = (long) fl; + timeout.tv_usec = (long) ((fl - timeout.tv_sec) * 1000000); + } time_p = &timeout; } diff --git a/libguile/posix.c b/libguile/posix.c index f0edefa6a..9a45ed91d 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -75,10 +75,6 @@ extern char *ttyname(); #include <libc.h> #endif -#ifdef HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif - #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -97,23 +93,6 @@ extern char *ttyname(); #include <signal.h> -#ifdef FD_SET - -#define SELECT_TYPE fd_set -#define SELECT_SET_SIZE FD_SETSIZE - -#else /* no FD_SET */ - -/* Define the macros to access a single-int bitmap of descriptors. */ -#define SELECT_SET_SIZE 32 -#define SELECT_TYPE int -#define FD_SET(n, p) (*(p) |= (1 << (n))) -#define FD_CLR(n, p) (*(p) &= ~(1 << (n))) -#define FD_ISSET(n, p) (*(p) & (1 << (n))) -#define FD_ZERO(p) (*(p) = 0) - -#endif /* no FD_SET */ - extern FILE *popen (); extern char ** environ; |