diff options
author | Stu Grossman <grossman@cygnus> | 1993-05-04 02:22:14 +0000 |
---|---|---|
committer | Stu Grossman <grossman@cygnus> | 1993-05-04 02:22:14 +0000 |
commit | 9775789df69c3d11e2eb1275c483b281e4581667 (patch) | |
tree | 51f80116f7162e04b51c533fd120a46ef3c317d6 | |
parent | f6dddd4e1da5f57905ba4593c07634b10109a8d0 (diff) | |
download | gdb-9775789df69c3d11e2eb1275c483b281e4581667.zip gdb-9775789df69c3d11e2eb1275c483b281e4581667.tar.gz gdb-9775789df69c3d11e2eb1275c483b281e4581667.tar.bz2 |
* ser-unix.c (wait_for): New routine to handle read timeouts,
etc. Uses poll() if HAVE_TERMIO[S] is defined, select() otherwise.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/ser-unix.c | 160 |
2 files changed, 68 insertions, 97 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4c6ab28..a73254c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +Mon May 3 19:20:20 1993 Stu Grossman (grossman@cygnus.com) + + * ser-unix.c (wait_for): New routine to handle read timeouts, + etc. Uses poll() if HAVE_TERMIO[S] is defined, select() otherwise. + Mon May 3 13:52:08 1993 Ian Lance Taylor (ian@cygnus.com) * mips-pinsn.c (print_insn): Return value. diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c index 3caccfa..32d22e2 100644 --- a/gdb/ser-unix.c +++ b/gdb/ser-unix.c @@ -21,24 +21,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "serial.h" #include <fcntl.h> #include <sys/types.h> - -/* Note: HAVE_SELECT is not yet defined on all the systems which could - define it. The USE_ALARM_TIMEOUT code seems to work OK, though, so - it doesn't really matter. */ -#if !defined (HAVE_SELECT) -#if defined (HAVE_TERMIO) -#define USE_TERMIO_TIMEOUT 1 -#else -#define USE_ALARM_TIMEOUT 1 -#endif -#endif - -#if defined (HAVE_SELECT) #include <sys/time.h> -#endif -#ifdef USE_ALARM_TIMEOUT -#include <signal.h> -#endif #if !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) && !defined (HAVE_SGTTY) #define HAVE_SGTTY @@ -47,14 +30,26 @@ 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> #endif +static int hardwire_open PARAMS ((serial_t scb, const char *name)); +static void hardwire_raw PARAMS ((serial_t scb)); +static int wait_for PARAMS ((serial_t scb, int timeout)); +static int hardwire_readchar PARAMS ((serial_t scb, int timeout)); +static int rate_to_code PARAMS ((int rate)); +static int hardwire_setbaudrate PARAMS ((serial_t scb, int rate)); +static int hardwire_write PARAMS ((serial_t scb, const char *str, int len)); +static void hardwire_restore PARAMS ((serial_t scb)); +static void hardwire_close PARAMS ((serial_t scb)); + /* Open up a real live device for serial I/O */ static int @@ -131,104 +126,74 @@ hardwire_raw(scb) #endif } -#ifdef USE_ALARM_TIMEOUT -/* Called when SIGALRM sent. */ -static void -remote_timer () -{ -} -#endif - -/* Read a character with user-specified timeout. TIMEOUT is number of seconds - to wait, or -1 to wait forever. Use timeout of 0 to effect a poll. Returns - char if successful. Returns -2 if timeout expired, EOF if line dropped - dead, or -3 for any other error (see errno in that case). */ +/* Wait for input on scb, with timeout seconds */ static int -hardwire_readchar(scb, timeout) +wait_for(scb, timeout) serial_t scb; int timeout; { - if (scb->bufcnt-- > 0) - return *scb->bufp++; + int numfds; -#ifdef HAVE_SELECT - { - int numfds; - struct timeval tv; - fd_set readfds; - - FD_ZERO (&readfds); +#ifdef HAVE_SGTTY + struct timeval tv; + fd_set readfds; - tv.tv_sec = timeout; - tv.tv_usec = 0; + FD_ZERO (&readfds); - FD_SET(scb->fd, &readfds); + tv.tv_sec = timeout; + tv.tv_usec = 0; - if (timeout >= 0) - numfds = select(scb->fd+1, &readfds, 0, 0, &tv); - else - numfds = select(scb->fd+1, &readfds, 0, 0, 0); + FD_SET(scb->fd, &readfds); - if (numfds <= 0) - if (numfds == 0) - return SERIAL_TIMEOUT; - else - return SERIAL_ERROR; /* Got an error from select */ + if (timeout >= 0) + numfds = select(scb->fd+1, &readfds, 0, 0, &tv); + else + numfds = select(scb->fd+1, &readfds, 0, 0, 0); - scb->bufcnt = read(scb->fd, scb->buf, BUFSIZ); - } -#endif /* HAVE_SELECT. */ +#endif /* HAVE_SGTTY */ -#ifdef USE_TERMIO_TIMEOUT - { - struct termio termio; +#if defined HAVE_TERMIO || defined HAVE_TERMIOS + struct pollfd pollfd; - if (ioctl (scb->fd, TCGETA, &termio)) - { - fprintf(stderr, "TCGETA failed: %s\n", safe_strerror(errno)); - } + pollfd.fd = scb->fd; + pollfd.events = POLLIN | POLLPRI; - termio.c_cc[VTIME] = timeout * 10; + if (timeout > 0) + timeout *= 1000; - if (ioctl (scb->fd, TCSETA, &termio)) - { - fprintf(stderr, "TCSETA failed: %s\n", safe_strerror(errno)); - } + numfds = poll(&pollfd, 1, timeout); - scb->bufcnt = read(scb->fd, scb->buf, BUFSIZ); - if (scb->bufcnt == 0) - /* Can this also mean end of file? Does "end of file" have any - meaning with ICANON clear? */ +#endif /* defined HAVE_TERMIO || defined HAVE_TERMIOS */ + + if (numfds <= 0) + if (numfds == 0) return SERIAL_TIMEOUT; - } -#endif /* USE_TERMIO_TIMEOUT. */ - -#ifdef USE_ALARM_TIMEOUT - { - void (*old_sigalrm_handler) (); - int save_errno; -#ifndef NO_SIGINTERRUPT - /* Cause SIGARLM to make read fail with EINTR. */ - if (siginterrupt (SIGALRM, 1) != 0) - fprintf (stderr, "siginterrupt failed: %s\n", safe_strerror (errno)); -#endif + else + return SERIAL_ERROR; /* Got an error from select or poll */ +} + +/* Read a character with user-specified timeout. TIMEOUT is number of seconds + to wait, or -1 to wait forever. Use timeout of 0 to effect a poll. Returns + char if successful. Returns -2 if timeout expired, EOF if line dropped + dead, or -3 for any other error (see errno in that case). */ + +static int +hardwire_readchar(scb, timeout) + serial_t scb; + int timeout; +{ + int status; + + if (scb->bufcnt-- > 0) + return *scb->bufp++; + + status = wait_for(scb, timeout); + + if (status < 0) + return status; - old_sigalrm_handler = (void (*) ()) signal (SIGALRM, remote_timer); - if (old_sigalrm_handler == (void (*) ()) -1) - fprintf (stderr, "signal failed: %s\n", safe_strerror (errno)); - - alarm (timeout); - scb->bufcnt = read(scb->fd, scb->buf, BUFSIZ); - save_errno = errno; - alarm (0); - signal (SIGALRM, old_sigalrm_handler); - if (scb->bufcnt < 0 && errno == EINTR) - { - return SERIAL_TIMEOUT; - } - } -#endif /* USE_ALARM_TIMEOUT */ + scb->bufcnt = read(scb->fd, scb->buf, BUFSIZ); if (scb->bufcnt <= 0) if (scb->bufcnt == 0) @@ -390,6 +355,7 @@ static struct serial_ops hardwire_ops = hardwire_setbaudrate }; +void _initialize_ser_hardwire () { serial_add_interface (&hardwire_ops); |