X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fser-unix.c;h=237384b3b7cd95ac68dfb438b256ca171413948e;hb=cef0333efd6b51706779c97e3646d542f3b0e381;hp=d14a996ed5554522c6952ab0065613b068eb3719;hpb=d881dd869fc70d807f3630328606c3d3cb3e83f9;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c index d14a996ed5..237384b3b7 100644 --- a/gdb/ser-unix.c +++ b/gdb/ser-unix.c @@ -1,5 +1,5 @@ /* Serial interface for local (hardwired) serial ports on Un*x like systems - Copyright 1992, 1993 Free Software Foundation, Inc. + Copyright 1992, 1993, 1994 Free Software Foundation, Inc. This file is part of GDB. @@ -353,7 +353,7 @@ hardwire_raw(scb) state.termios.c_oflag = 0; state.termios.c_lflag = 0; state.termios.c_cflag &= ~(CSIZE|PARENB); - state.termios.c_cflag |= CS8; + state.termios.c_cflag |= CLOCAL | CS8; state.termios.c_cc[VMIN] = 0; state.termios.c_cc[VTIME] = 0; #endif @@ -363,7 +363,7 @@ hardwire_raw(scb) state.termio.c_oflag = 0; state.termio.c_lflag = 0; state.termio.c_cflag &= ~(CSIZE|PARENB); - state.termio.c_cflag |= CS8; + state.termio.c_cflag |= CLOCAL | CS8; state.termio.c_cc[VMIN] = 0; state.termio.c_cc[VTIME] = 0; #endif @@ -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; - else - return SERIAL_ERROR; /* Got an error from select or poll */ - - return 0; - } + 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; + 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; @@ -435,15 +440,54 @@ wait_for(scb, timeout) fprintf_unfiltered(gdb_stderr, "get_tty_state failed: %s\n", safe_strerror(errno)); #ifdef HAVE_TERMIOS - state.termios.c_cc[VTIME] = timeout * 10; + if (timeout < 0) + { + /* No timeout. */ + state.termios.c_cc[VTIME] = 0; + state.termios.c_cc[VMIN] = 1; + } + else + { + state.termios.c_cc[VMIN] = 0; + state.termios.c_cc[VTIME] = timeout * 10; + if (state.termios.c_cc[VTIME] != timeout * 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 #ifdef HAVE_TERMIO - state.termio.c_cc[VTIME] = timeout * 10; + if (timeout < 0) + { + /* No timeout. */ + state.termio.c_cc[VTIME] = 0; + state.termio.c_cc[VMIN] = 1; + } + else + { + state.termio.c_cc[VMIN] = 0; + state.termio.c_cc[VTIME] = timeout * 10; + if (state.termio.c_cc[VTIME] != timeout * 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.termio.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)); @@ -467,24 +511,39 @@ 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 if (errno == EINTR) + continue; + else + return SERIAL_ERROR; /* Got an error from read */ + } + + scb->bufcnt--; + scb->bufp = scb->buf; + return *scb->bufp++; + } } #ifndef B19200