static int ser_base_wait_for (struct serial *scb, int timeout) { while (1) { int numfds; struct timeval tv; fd_set readfds, exceptfds; int nfds; /* NOTE: Some OS's can scramble the READFDS when the select() call fails (ex the kernel with Red Hat 5.2). Initialize all arguments before each call. */ tv.tv_sec = timeout; tv.tv_usec = 0; FD_ZERO (&readfds); FD_ZERO (&exceptfds); FD_SET (scb->fd, &readfds); FD_SET (scb->fd, &exceptfds); QUIT; nfds = scb->fd + 1; if (timeout >= 0) numfds = interruptible_select (nfds, &readfds, 0, &exceptfds, &tv); else numfds = interruptible_select (nfds, &readfds, 0, &exceptfds, 0); if (numfds <= 0) { if (numfds == 0) return SERIAL_TIMEOUT; else if (errno == EINTR) continue; else return SERIAL_ERROR; /* Got an error from select or poll. */ } return 0; } }
static int ioscm_input_waiting (SCM port) { int fdes = 0; if (! scm_is_eq (port, input_port_scm)) return 0; #ifdef HAVE_POLL { /* This is copied from libguile/fports.c. */ struct pollfd pollfd = { fdes, POLLIN, 0 }; static int use_poll = -1; if (use_poll < 0) { /* This is copied from event-loop.c: poll cannot be used for stdin on m68k-motorola-sysv. */ struct pollfd test_pollfd = { fdes, POLLIN, 0 }; if (poll (&test_pollfd, 1, 0) == 1 && (test_pollfd.revents & POLLNVAL)) use_poll = 0; else use_poll = 1; } if (use_poll) { /* Guile doesn't export SIGINT hooks like Python does. For now pass EINTR to scm_syserror, that's what fports.c does. */ if (poll (&pollfd, 1, 0) < 0) scm_syserror (FUNC_NAME); return pollfd.revents & POLLIN ? 1 : 0; } } /* Fall through. */ #endif { struct timeval timeout; fd_set input_fds; int num_fds = fdes + 1; int num_found; memset (&timeout, 0, sizeof (timeout)); FD_ZERO (&input_fds); FD_SET (fdes, &input_fds); num_found = interruptible_select (num_fds, &input_fds, NULL, NULL, &timeout); if (num_found < 0) { /* Guile doesn't export SIGINT hooks like Python does. For now pass EINTR to scm_syserror, that's what fports.c does. */ scm_syserror (FUNC_NAME); } return num_found > 0 && FD_ISSET (fdes, &input_fds); } }