From: Stu Grossman Date: Thu, 6 May 1993 22:17:10 +0000 (+0000) Subject: * ser-unix.c (wait_for): Use VTIME to do timeouts instead of X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9e15da4ac4bf432f090f654cb3dea987325f3334;p=binutils-gdb.git * ser-unix.c (wait_for): Use VTIME to do timeouts instead of poll() for termio{s}. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 77eeb9488b9..c2d4e4bf7f9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +Thu May 6 15:15:46 1993 Stu Grossman (grossman@cygnus.com) + + * ser-unix.c (wait_for): Use VTIME to do timeouts instead of + poll() for termio{s}. + Thu May 6 10:03:41 1993 Jim Kingdon (kingdon@cygnus.com) * i386-tdep.c (i386_frame_num_args): Always return -1. diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c index 32d22e29cb5..5f1622dfa2e 100644 --- a/gdb/ser-unix.c +++ b/gdb/ser-unix.c @@ -30,11 +30,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifdef HAVE_TERMIOS #include #include -#include #endif #ifdef HAVE_TERMIO #include -#include #endif #ifdef HAVE_SGTTY #include @@ -124,9 +122,16 @@ hardwire_raw(scb) if (ioctl (scb->fd, TIOCSETP, &sgttyb)) fprintf(stderr, "TIOCSETP failed: %s\n", safe_strerror(errno)); #endif + + scb->current_timeout = 0; } -/* Wait for input on scb, with timeout seconds */ +/* Wait for input on scb, with timeout seconds. Returns 0 on success, + otherwise SERIAL_TIMEOUT or SERIAL_ERROR. + + For termio{s}, we actually just setup VTIME if necessary, and let the + timeout occur in the read() in hardwire_read(). + */ static int wait_for(scb, timeout) @@ -151,26 +156,49 @@ wait_for(scb, timeout) else numfds = select(scb->fd+1, &readfds, 0, 0, 0); + if (numfds <= 0) + if (numfds == 0) + return SERIAL_TIMEOUT; + else + return SERIAL_ERROR; /* Got an error from select or poll */ + + return 0; + #endif /* HAVE_SGTTY */ #if defined HAVE_TERMIO || defined HAVE_TERMIOS - struct pollfd pollfd; + if (timeout == scb->current_timeout) + return 0; - pollfd.fd = scb->fd; - pollfd.events = POLLIN | POLLPRI; + { +#ifdef HAVE_TERMIOS + struct termios termios; - if (timeout > 0) - timeout *= 1000; + if (tcgetattr(scb->fd, &termios)) + fprintf(stderr, "wait_for() tcgetattr failed: %s\n", safe_strerror(errno)); - numfds = poll(&pollfd, 1, timeout); + termios.c_cc[VTIME] = timeout * 10; -#endif /* defined HAVE_TERMIO || defined HAVE_TERMIOS */ + if (tcsetattr(scb->fd, TCSANOW, &termios)) + fprintf(stderr, "wait_for() tcsetattr failed: %s\n", safe_strerror(errno)); +#endif /* HAVE_TERMIOS */ - if (numfds <= 0) - if (numfds == 0) - return SERIAL_TIMEOUT; - else - return SERIAL_ERROR; /* Got an error from select or poll */ +#ifdef HAVE_TERMIO + struct termio termio; + + if (ioctl (scb->fd, TCGETA, &termio)) + fprintf(stderr, "wait_for() TCGETA failed: %s\n", safe_strerror(errno)); + + termio.c_cc[VTIME] = timeout * 10; + + if (ioctl (scb->fd, TCSETA, &termio)) + fprintf(stderr, "TCSETA failed: %s\n", safe_strerror(errno)); +#endif /* HAVE_TERMIO */ + + scb->current_timeout = timeout; + return 0; + } +#endif /* HAVE_TERMIO || HAVE_TERMIOS */ } /* Read a character with user-specified timeout. TIMEOUT is number of seconds @@ -197,7 +225,9 @@ hardwire_readchar(scb, timeout) if (scb->bufcnt <= 0) if (scb->bufcnt == 0) - return SERIAL_EOF; /* 0 chars means end of file */ + return SERIAL_TIMEOUT; /* 0 chars means timeout [may need to + distinguish between EOF & timeouts + someday] */ else return SERIAL_ERROR; /* Got an error from read */