From 747e88d3f6c0a4007dd32b315700246d21e21ecb Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 30 Jan 2001 01:52:29 +0000 Subject: [PATCH] * fhandler_serial.cc (raw_write): Use local copy of OVERLAPPED structure instead of shared structure to fix a race condition between read/write. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/fhandler_serial.cc | 16 +++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 7611e3d4f..3395c3438 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +Mon Jan 29 17:15:22 2001 Bill Hegardt + + * fhandler_serial.cc (raw_write): Use local copy of OVERLAPPED + structure instead of shared structure to fix a race condition between + read/write. + Mon Jan 29 14:30:00 2001 Corinna Vinschen * mmap.cc (mmap): Remove obsolete check for MAP_SHARED|MAP_ANON as 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; }