Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/fhandler_serial.cc')
-rw-r--r--winsup/cygwin/fhandler_serial.cc35
1 files changed, 16 insertions, 19 deletions
diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc
index 96b4062f1..677b6221f 100644
--- a/winsup/cygwin/fhandler_serial.cc
+++ b/winsup/cygwin/fhandler_serial.cc
@@ -19,13 +19,7 @@ details. */
#include "sigproc.h"
#include "pinfo.h"
#include <asm/socket.h>
-#ifdef __MINGW64_VERSION_MAJOR
-#include <devioctl.h>
-#include <ntddser.h>
-#else
#include <ddk/ntddser.h>
-#endif
-#include "cygwait.h"
/**********************************************************************/
/* fhandler_serial */
@@ -77,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 (!is_nonblocking () && !overlapped_armed)
+ else if (!overlapped_armed)
{
if ((size_t) tot >= minchars)
break;
@@ -89,6 +83,16 @@ 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;
@@ -100,13 +104,13 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen)
goto err;
debug_printf ("n %d, ev %x", n, ev);
break;
- case WAIT_SIGNALED:
+ case WAIT_OBJECT_0 + 1:
tot = -1;
PurgeComm (get_handle (), PURGE_RXABORT);
overlapped_armed = 0;
set_sig_errno (EINTR);
goto out;
- case WAIT_CANCELED:
+ case WAIT_OBJECT_0 + 2:
PurgeComm (get_handle (), PURGE_RXABORT);
overlapped_armed = 0;
pthread::static_cancel_self ();
@@ -128,14 +132,7 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen)
goto err;
else if (is_nonblocking ())
{
- /* 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_OPERATION_ABORTED)
- goto err;
+ PurgeComm (get_handle (), PURGE_RXABORT);
if (tot == 0)
{
tot = -1;
@@ -207,12 +204,12 @@ fhandler_serial::raw_write (const void *ptr, size_t len)
{
case WAIT_OBJECT_0:
break;
- case WAIT_SIGNALED:
+ case WAIT_OBJECT_0 + 1:
PurgeComm (get_handle (), PURGE_TXABORT);
set_sig_errno (EINTR);
ForceCloseHandle (write_status.hEvent);
return -1;
- case WAIT_CANCELED:
+ case WAIT_OBJECT_0 + 2:
PurgeComm (get_handle (), PURGE_TXABORT);
pthread::static_cancel_self ();
/*NOTREACHED*/