From 4febd10272e10062f09c8456dacd8cfe970579d8 Mon Sep 17 00:00:00 2001 From: Stu Grossman Date: Fri, 9 Apr 1993 22:14:04 +0000 Subject: [PATCH] * remote.c (remote_open): Use SERIAL_OPEN instead of serial_open. (putpkt, getpkt): Use new return codes for SERIAL_READCHAR. * ser-go32.c: Return -1 on most failures, 0 on most successes, and use new return codes for go32_readchar(). * ser-unix.c: Ditto. Also, move error handling up to caller for SERIAL_SETBAUDRATE(). * serial.c (serial_open): Internal call, not SERIAL_OPEN to get to specific routine. (serial_close): New routine to wrap around device close routine. serial.h: Clean & document return values more clearly. --- gdb/ChangeLog | 13 +++++++++++++ gdb/ser-go32.c | 10 ++++++---- gdb/ser-unix.c | 31 ++++++++++++------------------- gdb/serial.c | 11 ++++++++++- gdb/serial.h | 39 ++++++++++++++++++++++++--------------- 5 files changed, 65 insertions(+), 39 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 46251b705c5..4d557189130 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +Fri Apr 9 15:01:12 1993 Stu Grossman (grossman@cygnus.com) + + * remote.c (remote_open): Use SERIAL_OPEN instead of serial_open. + (putpkt, getpkt): Use new return codes for SERIAL_READCHAR. + * ser-go32.c: Return -1 on most failures, 0 on most successes, + and use new return codes for go32_readchar(). + * ser-unix.c: Ditto. Also, move error handling up to caller for + SERIAL_SETBAUDRATE(). + * serial.c (serial_open): Internal call, not SERIAL_OPEN to get + to specific routine. + (serial_close): New routine to wrap around device close routine. + serial.h: Clean & document return values more clearly. + Fri Apr 9 10:20:55 1993 Jim Kingdon (kingdon@cygnus.com) * rs6000-pinsn.c (print_operand): Deal with no operand instructions. diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c index 844f8613fda..1d930a88480 100644 --- a/gdb/ser-go32.c +++ b/gdb/ser-go32.c @@ -222,7 +222,7 @@ go32_open (scb, name) if (strncasecmp (name, "com", 3) != 0) { errno = ENOENT; - return 1; + return -1; } port = name[3] - '0'; @@ -230,12 +230,12 @@ go32_open (scb, name) if ((port != 1) && (port != 2)) { errno = ENOENT; - return 1; + return -11; } scb->fd = dos_async_init(port); if (!scb->fd) - return 1; + return -1; return 0; } @@ -257,7 +257,7 @@ go32_readchar (scb, timeout) if (dosasync_read(scb->fd, &buf, 1, timeout)) return buf; else - return -2; /* Timeout, I guess */ + return SERIAL_TIMEOUT; } static int @@ -275,6 +275,8 @@ go32_write (scb, str, len) int len; { dosasync_write(scb->fd, str, len); + + return 0; } static void diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c index 541e4c21add..afe6724221c 100644 --- a/gdb/ser-unix.c +++ b/gdb/ser-unix.c @@ -47,7 +47,7 @@ hardwire_open(scb, name) { scb->fd = open (name, O_RDWR); if (scb->fd < 0) - return errno; + return -1; return 0; } @@ -145,17 +145,17 @@ hardwire_readchar(scb, timeout) if (numfds <= 0) if (numfds == 0) - return -2; /* Timeout */ + return SERIAL_TIMEOUT; else - return -3; /* Got an error from select */ + return SERIAL_ERROR; /* Got an error from select */ scb->bufcnt = read(scb->fd, scb->buf, BUFSIZ); if (scb->bufcnt <= 0) if (scb->bufcnt == 0) - return EOF; /* 0 chars means end of file */ + return SERIAL_EOF; /* 0 chars means end of file */ else - return -3; /* Got an error from read */ + return SERIAL_ERROR; /* Got an error from read */ scb->bufcnt--; scb->bufp = scb->buf; @@ -220,24 +220,20 @@ hardwire_setbaudrate(scb, rate) struct termios termios; if (tcgetattr (scb->fd, &termios)) - error("hardwire_setbaudrate: tcgetattr failed: %s\n", safe_strerror(errno)); + return -1; cfsetospeed (&termios, rate_to_code (rate)); cfsetispeed (&termios, rate_to_code (rate)); if (tcsetattr (scb->fd, TCSANOW, &termios)) - error ("hardwire_setbaudrate: tcsetattr failed: %s\n", safe_strerror(errno)); - - return 1; + return -1; #endif #ifdef HAVE_TERMIO struct termio termio; if (ioctl (scb->fd, TCGETA, &termio)) - { - fprintf(stderr, "TCGETA failed: %s\n", safe_strerror(errno)); - } + return -1; #ifndef CIBAUD #define CIBAUD CBAUD @@ -247,23 +243,22 @@ hardwire_setbaudrate(scb, rate) termio.c_cflag |= rate_to_code (rate); if (ioctl (scb->fd, TCSETA, &termio)) - { - fprintf(stderr, "TCSETA failed: %s\n", safe_strerror(errno)); - } + return -1; #endif #ifdef HAVE_SGTTY struct sgttyb sgttyb; if (ioctl (scb->fd, TIOCGETP, &sgttyb)) - fprintf (stderr, "TIOCGETP failed: %s\n", safe_strerror (errno)); + return -1; sgttyb.sg_ispeed = rate_to_code (rate); sgttyb.sg_ospeed = rate_to_code (rate); if (ioctl (scb->fd, TIOCSETP, &sgttyb)) - fprintf (stderr, "TIOCSETP failed: %s\n", safe_strerror (errno)); + return -1; #endif + return 0; } static int @@ -299,8 +294,6 @@ hardwire_close(scb) if (scb->fd < 0) return; - SERIAL_RESTORE(scb); - close(scb->fd); scb->fd = -1; } diff --git a/gdb/serial.c b/gdb/serial.c index 5a4fcf42398..e4c8cbf10b7 100644 --- a/gdb/serial.c +++ b/gdb/serial.c @@ -64,7 +64,7 @@ serial_open(name) scb->bufcnt = 0; scb->bufp = scb->buf; - if (SERIAL_OPEN (scb, name)) + if (scb->ops->open(scb, name)) { free (scb); return NULL; @@ -73,6 +73,15 @@ serial_open(name) return scb; } +void +serial_close(scb) + serial_t scb; +{ + scb->ops->close(scb); + + free(scb); +} + #if 0 /* Connect the user directly to the remote system. This command acts just like the 'cu' or 'tip' command. Use ~. or ~^D to break out. */ diff --git a/gdb/serial.h b/gdb/serial.h index 767a91b3161..1fbd488c8b6 100644 --- a/gdb/serial.h +++ b/gdb/serial.h @@ -49,38 +49,47 @@ struct serial_ops { void serial_add_interface PARAMS ((struct serial_ops *optable)); -/* Try to open the serial device "name", returns a serial_t if ok, NULL if not. - */ - serial_t serial_open PARAMS ((const char *name)); -/* Internal open routine for specific I/O interface */ +/* For most routines, if a failure is indicated, then errno should be + examined. */ + +/* Try to open NAME. Returns a new serial_t on success, NULL on failure. + */ -#define SERIAL_OPEN(SERIAL_T, NAME) (SERIAL_T)->ops->open((SERIAL_T), NAME) +#define SERIAL_OPEN(NAME) serial_open(NAME) -/* Turn the port into raw mode. */ +/* Turn the port into raw mode. */ #define SERIAL_RAW(SERIAL_T) (SERIAL_T)->ops->go_raw((SERIAL_T)) -/* Read one char from the serial device with -second timeout. - Returns char if ok, else EOF, -2 for timeout, -3 for anything else */ +/* Read one char from the serial device with TIMEOUT seconds timeout. + Returns char if ok, else one of the following codes. Note that all + error codes are guaranteed to be < 0. */ + +#define SERIAL_ERROR -1 /* General error, see errno for details */ +#define SERIAL_TIMEOUT -2 +#define SERIAL_EOF -3 #define SERIAL_READCHAR(SERIAL_T, TIMEOUT) ((SERIAL_T)->ops->readchar((SERIAL_T), TIMEOUT)) -/* Set the baudrate to the decimal value supplied. Return 1 on failure, - 0 otherwise. */ +/* Set the baudrate to the decimal value supplied. Returns 0 for success, + -1 for failure. */ #define SERIAL_SETBAUDRATE(SERIAL_T, RATE) ((SERIAL_T)->ops->setbaudrate((SERIAL_T), RATE)) -/* Write some chars to the device, returns 0 for failure. See errno for - details. */ +/* Write LEN chars from STRING to the port SERIAL_T. Returns 0 for success, + -1 for failure. */ #define SERIAL_WRITE(SERIAL_T, STRING, LEN) ((SERIAL_T)->ops->write((SERIAL_T), STRING, LEN)) -/* Close the serial port */ +/* Push out all buffers, close the device and destroy SERIAL_T. */ + +void serial_close PARAMS ((serial_t)); -#define SERIAL_CLOSE(SERIAL_T) (SERIAL_T)->ops->close((SERIAL_T)) +#define SERIAL_CLOSE(SERIAL_T) serial_close(SERIAL_T) -/* Restore the serial port to the state saved in oldstate */ +/* Restore the serial port to the state saved in oldstate. XXX - currently + unused! */ #define SERIAL_RESTORE(SERIAL_T) (SERIAL_T)->ops->restore((SERIAL_T)) -- 2.30.2