diff options
author | Jim Kingdon <jkingdon@engr.sgi.com> | 1994-01-29 16:12:35 +0000 |
---|---|---|
committer | Jim Kingdon <jkingdon@engr.sgi.com> | 1994-01-29 16:12:35 +0000 |
commit | 9db58d3ab42b7f4fd3b4b4aa80bcb6404ce32b0d (patch) | |
tree | dbff8100177f7e742fea96bed1564a324683d0b1 /gdb/ser-unix.c | |
parent | f28c6e3813995dcd511ab74f41bdacb6f53fa27d (diff) | |
download | gdb-9db58d3ab42b7f4fd3b4b4aa80bcb6404ce32b0d.zip gdb-9db58d3ab42b7f4fd3b4b4aa80bcb6404ce32b0d.tar.gz gdb-9db58d3ab42b7f4fd3b4b4aa80bcb6404ce32b0d.tar.bz2 |
* ser-unix.c (wait_for, hardwire_readchar) [HAVE_TERMIO, HAVE_TERMIOS]:
If the timeout is too big to fit in c_cc[VTIME], then do multiple reads
to achieve the desired timeout.
* serial.h (serial_t): Add field timeout_remaining.
Diffstat (limited to 'gdb/ser-unix.c')
-rw-r--r-- | gdb/ser-unix.c | 121 |
1 files changed, 74 insertions, 47 deletions
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c index 0e490fb..6c09b31 100644 --- a/gdb/ser-unix.c +++ b/gdb/ser-unix.c @@ -391,43 +391,48 @@ wait_for(scb, timeout) serial_t scb; int timeout; { + scb->timeout_remaining = 0; + #ifdef HAVE_SGTTY - struct timeval tv; - fd_set readfds; + { + struct timeval tv; + fd_set readfds; - FD_ZERO (&readfds); + FD_ZERO (&readfds); - tv.tv_sec = timeout; - tv.tv_usec = 0; + tv.tv_sec = timeout; + tv.tv_usec = 0; - FD_SET(scb->fd, &readfds); + FD_SET(scb->fd, &readfds); - while (1) - { - int numfds; - - if (timeout >= 0) - numfds = select(scb->fd+1, &readfds, 0, 0, &tv); - else - numfds = select(scb->fd+1, &readfds, 0, 0, 0); - - if (numfds <= 0) - if (numfds == 0) - return SERIAL_TIMEOUT; - else if (errno == EINTR) - continue; + while (1) + { + int numfds; + + if (timeout >= 0) + numfds = select(scb->fd+1, &readfds, 0, 0, &tv); else - return SERIAL_ERROR; /* Got an error from select or poll */ + numfds = select(scb->fd+1, &readfds, 0, 0, 0); - return 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; + } + } #endif /* HAVE_SGTTY */ #if defined HAVE_TERMIO || defined HAVE_TERMIOS if (timeout == scb->current_timeout) return 0; + scb->current_timeout = timeout; + { struct hardwire_ttystate state; @@ -447,8 +452,14 @@ wait_for(scb, timeout) state.termios.c_cc[VTIME] = timeout * 10; if (state.termios.c_cc[VTIME] != timeout * 10) { - warning ("Timeout value %d too large, using %d", timeout, - state.termios.c_cc[VTIME] / 10); + + /* If c_cc is an 8-bit signed character, we can't go + bigger than this. If it is always unsigned, we could use + 25. */ + + scb->current_timeout = 12; + state.termios.c_cc[VTIME] = scb->current_timeout * 10; + scb->timeout_remaining = timeout - scb->current_timeout; } } #endif @@ -466,14 +477,17 @@ wait_for(scb, timeout) state.termio.c_cc[VTIME] = timeout * 10; if (state.termio.c_cc[VTIME] != timeout * 10) { - warning ("Timeout value %d too large, using %d", timeout, - state.termio.c_cc[VTIME] / 10); + /* If c_cc is an 8-bit signed character, we can't go + bigger than this. If it is always unsigned, we could use + 25. */ + + scb->current_timeout = 12; + state.termios.c_cc[VTIME] = scb->current_timeout * 10; + scb->timeout_remaining = timeout - scb->current_timeout; } } #endif - scb->current_timeout = timeout; - if (set_tty_state (scb, &state)) fprintf_unfiltered(gdb_stderr, "set_tty_state failed: %s\n", safe_strerror(errno)); @@ -497,24 +511,37 @@ hardwire_readchar(scb, timeout) if (scb->bufcnt-- > 0) return *scb->bufp++; - status = wait_for(scb, timeout); - - if (status < 0) - return status; - - scb->bufcnt = read(scb->fd, scb->buf, BUFSIZ); - - if (scb->bufcnt <= 0) - if (scb->bufcnt == 0) - return SERIAL_TIMEOUT; /* 0 chars means timeout [may need to - distinguish between EOF & timeouts - someday] */ - else - return SERIAL_ERROR; /* Got an error from read */ - - scb->bufcnt--; - scb->bufp = scb->buf; - return *scb->bufp++; + while (1) + { + status = wait_for (scb, timeout); + + if (status < 0) + return status; + + scb->bufcnt = read (scb->fd, scb->buf, BUFSIZ); + + if (scb->bufcnt <= 0) + { + if (scb->bufcnt == 0) + { + /* Zero characters means timeout (it could also be EOF, but + we don't (yet at least) distinguish). */ + if (scb->timeout_remaining > 0) + { + timeout = scb->timeout_remaining; + continue; + } + else + return SERIAL_TIMEOUT; + } + else + return SERIAL_ERROR; /* Got an error from read */ + } + + scb->bufcnt--; + scb->bufp = scb->buf; + return *scb->bufp++; + } } #ifndef B19200 |