1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 19:50:24 +02:00

* 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.
This commit is contained in:
Gary Houston 1997-05-15 08:46:37 +00:00
parent 223be5f043
commit a48a89bc17
3 changed files with 108 additions and 68 deletions

View file

@ -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> Wed May 14 12:18:12 1997 Jim Blandy <jimb@floss.cyclic.com>
* strports.c (scm_eval_string): New function. * strports.c (scm_eval_string): New function.

View file

@ -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 static void
fill_select_type (set, list) fill_select_type (SELECT_TYPE *set, SCM list)
SELECT_TYPE * set;
SCM list;
{ {
while (list != SCM_EOL) if (SCM_NIMP (list) && SCM_VECTORP (list))
{ {
if ( SCM_NIMP (SCM_CAR (list)) int len = SCM_LENGTH (list);
&& (scm_tc16_fport == SCM_TYP16 (SCM_CAR (list))) SCM *ve = SCM_VELTS (list);
&& SCM_OPPORTP (SCM_CAR (list)))
FD_SET (fileno ((FILE *)SCM_STREAM (SCM_CAR (list))), set); while (len > 0)
else if (SCM_INUMP (SCM_CAR (list))) {
FD_SET (SCM_INUM (SCM_CAR (list)), set); set_element (set, ve[len - 1]);
list = SCM_CDR (list); len--;
}
}
else
{
while (list != SCM_EOL)
{
set_element (set, SCM_CAR (list));
list = SCM_CDR (list);
}
} }
} }
static SCM
static SCM retrieve_select_type SCM_P ((SELECT_TYPE * set, SCM list)); 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 static SCM
retrieve_select_type (set, list) retrieve_select_type (SELECT_TYPE *set, SCM list)
SELECT_TYPE * set;
SCM list;
{ {
SCM answer; SCM answer_list = SCM_EOL;
answer = SCM_EOL;
while (list != SCM_EOL) if (SCM_NIMP (list) && SCM_VECTORP (list))
{ {
if ( SCM_NIMP (SCM_CAR (list)) int len = SCM_LENGTH (list);
&& (scm_tc16_fport == SCM_TYP16 (SCM_CAR (list))) SCM *ve = SCM_VELTS (list);
&& SCM_OPPORTP (SCM_CAR (list)))
while (len > 0)
{ {
if (FD_ISSET (fileno ((FILE *)SCM_STREAM (SCM_CAR (list))), set)) answer_list = get_element (set, ve[len - 1], answer_list);
answer = scm_cons (SCM_CAR (list), answer); len--;
} }
else if (SCM_INUMP (SCM_CAR (list))) return scm_vector (answer_list);
{ }
if (FD_ISSET (SCM_INUM (SCM_CAR (list)), set)) else
answer = scm_cons (SCM_CAR (list), answer); {
} /* list is a list. */
list = SCM_CDR (list); while (list != SCM_EOL)
{
answer_list = get_element (set, SCM_CAR (list), answer_list);
list = SCM_CDR (list);
}
return answer_list;
} }
return answer;
} }
/* {Checking for events}
*/
SCM_PROC (s_select, "select", 3, 2, 0, scm_select); SCM_PROC (s_select, "select", 3, 2, 0, scm_select);
SCM SCM
scm_select (reads, writes, excepts, secs, msecs) scm_select (reads, writes, excepts, secs, usecs)
SCM reads; SCM reads;
SCM writes; SCM writes;
SCM excepts; SCM excepts;
SCM secs; SCM secs;
SCM msecs; SCM usecs;
{ {
#ifdef HAVE_SELECT #ifdef HAVE_SELECT
struct timeval timeout; struct timeval timeout;
@ -787,9 +817,13 @@ scm_select (reads, writes, excepts, secs, msecs)
SELECT_TYPE except_set; SELECT_TYPE except_set;
int sreturn; int sreturn;
SCM_ASSERT (-1 < scm_ilength (reads), reads, SCM_ARG1, s_select); #define assert_set(x, arg) \
SCM_ASSERT (-1 < scm_ilength (writes), reads, SCM_ARG1, s_select); SCM_ASSERT (scm_ilength (x) > -1 || (SCM_NIMP (x) && SCM_VECTORP (x)), \
SCM_ASSERT (-1 < scm_ilength (excepts), reads, SCM_ARG1, s_select); 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 (&read_set);
FD_ZERO (&write_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 (&write_set, writes);
fill_select_type (&except_set, excepts); fill_select_type (&except_set, excepts);
if (SCM_UNBNDP (secs)) if (SCM_UNBNDP (secs) || SCM_FALSEP (secs))
time_p = 0; time_p = 0;
else else
{ {
SCM_ASSERT (SCM_INUMP (secs), secs, SCM_ARG4, s_select); if (SCM_INUMP (secs))
if (SCM_UNBNDP (msecs)) {
msecs = SCM_INUM0; 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 else
SCM_ASSERT (SCM_INUMP (msecs), msecs, SCM_ARG5, s_select); {
double fl = scm_num2dbl (secs, s_select);
timeout.tv_sec = SCM_INUM (secs); if (!SCM_UNBNDP (usecs))
timeout.tv_usec = 1000 * SCM_INUM (msecs); 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; time_p = &timeout;
} }

View file

@ -75,10 +75,6 @@ extern char *ttyname();
#include <libc.h> #include <libc.h>
#endif #endif
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@ -97,23 +93,6 @@ extern char *ttyname();
#include <signal.h> #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 FILE *popen ();
extern char ** environ; extern char ** environ;