diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2003-12-11 18:07:42 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2003-12-11 18:07:42 +0000 |
commit | 97cb9b9de404248a3c117a2f391696732ce6e860 (patch) | |
tree | 11dcae6cf62bd0730697d1bc6ebfd8f586ed2a4c | |
parent | 992406a5ea5adc93a4906ca6e4487efc5f28956e (diff) | |
download | newlib-97cb9b9de404248a3c117a2f391696732ce6e860.zip newlib-97cb9b9de404248a3c117a2f391696732ce6e860.tar.gz newlib-97cb9b9de404248a3c117a2f391696732ce6e860.tar.bz2 |
* fhandler_serial.cc (fhandler_serial::tcflush): Simplify. Remove
read polling loop to avoid a hang with streaming devices.
-rw-r--r-- | winsup/cygwin/ChangeLog | 5 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_serial.cc | 37 |
2 files changed, 28 insertions, 14 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 899282a..3d1cab7 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2003-12-11 Brian Ford <ford@vss.fsi.com> + + * fhandler_serial.cc (fhandler_serial::tcflush): Simplify. Remove + read polling loop to avoid a hang with streaming devices. + 2003-12-11 Christopher Faylor <cgf@redhat.com> * pinfo.cc (_pinfo::set_ctty): Correct stupid typo. diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc index af39412..efb1af9 100644 --- a/winsup/cygwin/fhandler_serial.cc +++ b/winsup/cygwin/fhandler_serial.cc @@ -497,21 +497,30 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer) int fhandler_serial::tcflush (int queue) { - if (queue == TCOFLUSH || queue == TCIOFLUSH) - PurgeComm (get_handle (), PURGE_TXABORT | PURGE_TXCLEAR); + DWORD flags; - if (queue == TCIFLUSH || queue == TCIOFLUSH) - /* Input flushing by polling until nothing turns up - (we stop after 1000 chars anyway) */ - for (int max = 1000; max > 0; max--) - { - COMSTAT st; - if (!PurgeComm (get_handle (), PURGE_RXABORT | PURGE_RXCLEAR)) - break; - low_priority_sleep (100); - if (!ClearCommError (get_handle (), &ev, &st) || !st.cbInQue) - break; - } + switch (queue) + { + case TCOFLUSH: + flags = PURGE_TXABORT | PURGE_TXCLEAR; + break; + case TCIFLUSH: + flags = PURGE_RXABORT | PURGE_RXCLEAR; + break; + case TCIOFLUSH: + flags = PURGE_TXABORT | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_RXCLEAR; + break; + default: + termios_printf ("Invalid tcflush queue %d", queue); + set_errno (EINVAL); + return -1; + } + + if (!PurgeComm (get_handle (), flags)) + { + __seterrno (); + return -1; + } return 0; } |