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:
authorChristopher Faylor <me@cgf.cx>2001-01-30 04:52:29 +0300
committerChristopher Faylor <me@cgf.cx>2001-01-30 04:52:29 +0300
commit747e88d3f6c0a4007dd32b315700246d21e21ecb (patch)
treef42ad889aed0ffa5f885dafb1cb48a5bcd3118d5 /winsup/cygwin/fhandler_serial.cc
parent3aaa66f813d099dbb04e637459e168800d231aa3 (diff)
* fhandler_serial.cc (raw_write): Use local copy of OVERLAPPED structure
instead of shared structure to fix a race condition between read/write.
Diffstat (limited to 'winsup/cygwin/fhandler_serial.cc')
-rw-r--r--winsup/cygwin/fhandler_serial.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc
index 838da6b9d..62c02abe4 100644
--- a/winsup/cygwin/fhandler_serial.cc
+++ b/winsup/cygwin/fhandler_serial.cc
@@ -161,15 +161,15 @@ int
fhandler_serial::raw_write (const void *ptr, size_t len)
{
DWORD bytes_written;
+ OVERLAPPED write_status;
- if (overlapped_armed)
- PurgeComm (get_handle (), PURGE_TXABORT | PURGE_RXABORT);
- ResetEvent (io_status.hEvent);
+ memset (&write_status, 0, sizeof (write_status));
+ write_status.hEvent = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
+ ProtectHandle (write_status.hEvent);
for (;;)
{
- overlapped_armed = TRUE;
- if (WriteFile (get_handle(), ptr, len, &bytes_written, &io_status))
+ if (WriteFile (get_handle(), ptr, len, &bytes_written, &write_status))
break;
switch (GetLastError ())
@@ -182,17 +182,19 @@ fhandler_serial::raw_write (const void *ptr, size_t len)
goto err;
}
- if (!GetOverlappedResult (get_handle (), &io_status, &bytes_written, TRUE))
+ if (!GetOverlappedResult (get_handle (), &write_status, &bytes_written, TRUE))
goto err;
break;
}
- overlapped_armed = FALSE;
+ CloseHandle(write_status.hEvent);
+
return bytes_written;
err:
__seterrno ();
+ CloseHandle(write_status.hEvent);
return -1;
}