diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2012-05-25 09:29:17 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2012-05-25 09:29:17 +0000 |
commit | 96d5b7d17cdbbf265f3be6d5cc7894ff915bc1c3 (patch) | |
tree | a8832a3e7c8500805d446342ef26c7456bd112a3 /winsup/cygwin/fhandler_serial.cc | |
parent | 79f6dbe17185c80cae5d25d26aa43e549b8ac202 (diff) | |
download | cygnal-96d5b7d17cdbbf265f3be6d5cc7894ff915bc1c3.tar.gz cygnal-96d5b7d17cdbbf265f3be6d5cc7894ff915bc1c3.tar.bz2 cygnal-96d5b7d17cdbbf265f3be6d5cc7894ff915bc1c3.zip |
* fhandler_serial.cc (fhandler_serial::raw_read): Just call ReadFile
directly in case of non-blocking I/O and handle result gracefully.
Diffstat (limited to 'winsup/cygwin/fhandler_serial.cc')
-rw-r--r-- | winsup/cygwin/fhandler_serial.cc | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc index 677b6221f..c58d0418c 100644 --- a/winsup/cygwin/fhandler_serial.cc +++ b/winsup/cygwin/fhandler_serial.cc @@ -71,7 +71,7 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen) termios_printf ("error detected %x", ev); else if (st.cbInQue && !vtime_) inq = st.cbInQue; - else if (!overlapped_armed) + else if (!is_nonblocking () && !overlapped_armed) { if ((size_t) tot >= minchars) break; @@ -83,16 +83,6 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen) } else if (GetLastError () != ERROR_IO_PENDING) goto err; - else if (is_nonblocking ()) - { - PurgeComm (get_handle (), PURGE_RXABORT); - if (tot == 0) - { - tot = -1; - set_errno (EAGAIN); - } - goto out; - } else { overlapped_armed = 1; @@ -132,7 +122,14 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen) goto err; else if (is_nonblocking ()) { - PurgeComm (get_handle (), PURGE_RXABORT); + /* Use CancelIo rather than PurgeComm (PURGE_RXABORT) since + PurgeComm apparently discards in-flight bytes while CancelIo + only stops the overlapped IO routine. */ + CancelIo (get_handle ()); + if (GetOverlappedResult (get_handle (), &io_status, &n, FALSE)) + tot = n; + else if (GetLastError () != ERROR_IO_INCOMPLETE) + goto err; if (tot == 0) { tot = -1; |