diff options
author | Stu Grossman <grossman@cygnus> | 1993-05-06 22:17:10 +0000 |
---|---|---|
committer | Stu Grossman <grossman@cygnus> | 1993-05-06 22:17:10 +0000 |
commit | 9e15da4ac4bf432f090f654cb3dea987325f3334 (patch) | |
tree | 239b5207105da344037617e178a6fd5434e711f6 /gdb | |
parent | dfa592fb5ae5db2bfe3130e73128e1d08f562ece (diff) | |
download | gdb-9e15da4ac4bf432f090f654cb3dea987325f3334.zip gdb-9e15da4ac4bf432f090f654cb3dea987325f3334.tar.gz gdb-9e15da4ac4bf432f090f654cb3dea987325f3334.tar.bz2 |
* ser-unix.c (wait_for): Use VTIME to do timeouts instead of
poll() for termio{s}.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/ser-unix.c | 62 |
2 files changed, 51 insertions, 16 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 77eeb94..c2d4e4b 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 32d22e2..5f1622d 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 <termios.h> #include <unistd.h> -#include <poll.h> #endif #ifdef HAVE_TERMIO #include <termio.h> -#include <poll.h> #endif #ifdef HAVE_SGTTY #include <sgtty.h> @@ -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 */ |