--- tme/host/posix/posix-serial.c 2018/04/24 16:37:52 1.1.1.1 +++ tme/host/posix/posix-serial.c 2018/04/24 16:42:23 1.1.1.3 @@ -1,6 +1,6 @@ -/* $Id: posix-serial.c,v 1.1.1.1 2018/04/24 16:37:52 root Exp $ */ +/* $Id: posix-serial.c,v 1.1.1.3 2018/04/24 16:42:23 root Exp $ */ -/* host/posix/serial.c - implementation of serial ports on a POSIX system: */ +/* host/posix/posix-serial.c - implementation of serial ports on a POSIX system: */ /* * Copyright (c) 2003 Matt Fredette @@ -34,7 +34,7 @@ */ #include -_TME_RCSID("$Id: posix-serial.c,v 1.1.1.1 2018/04/24 16:37:52 root Exp $"); +_TME_RCSID("$Id: posix-serial.c,v 1.1.1.3 2018/04/24 16:42:23 root Exp $"); /* includes: */ #include @@ -208,13 +208,17 @@ _tme_posix_serial_th_ctrl(struct tme_pos for (;;) { /* get the modem state of the input device: */ - ioctl(serial->tme_posix_serial_fd_in, TIOCMGET, &modem_state); + if (ioctl(serial->tme_posix_serial_fd_in, TIOCMGET, &modem_state) < 0) { + modem_state = 0; + } /* if the output device is different, get the modem state of the output device and merge it in: */ if (serial->tme_posix_serial_fd_out != serial->tme_posix_serial_fd_in) { - ioctl(serial->tme_posix_serial_fd_in, TIOCMGET, &modem_state_out); + if (ioctl(serial->tme_posix_serial_fd_in, TIOCMGET, &modem_state_out) < 0) { + modem_state_out = 0; + } modem_state &= ~(TIOCM_DTR | TIOCM_RTS | TIOCM_CTS); modem_state |= modem_state_out & ~(TIOCM_CD | TIOCM_RI | TIOCM_DSR); } @@ -335,11 +339,16 @@ _tme_posix_serial_th_reader(struct tme_p sizeof(buffer_input)); /* if the read failed: */ - if (rc <= 0) { + if (rc < 0) { /* XXX diagnostic */ continue; } + /* if we hit EOF: */ + if (rc == 0) { + return; + } + /* lock the mutex: */ tme_mutex_lock(&serial->tme_posix_serial_mutex); @@ -802,8 +811,7 @@ _tme_posix_serial_connections_new(struct serial = (struct tme_posix_serial *) element->tme_element_private; /* if this serial is already connected, we can do nothing: */ - if (TME_ATOMIC_READ(struct tme_serial_connection *, - serial->tme_posix_serial_connection) != NULL) { + if (serial->tme_posix_serial_connection != NULL) { return (EISCONN); }