diff options
author | Christopher Faylor <me@cgf.cx> | 2001-01-30 04:52:29 +0300 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2001-01-30 04:52:29 +0300 |
commit | 747e88d3f6c0a4007dd32b315700246d21e21ecb (patch) | |
tree | f42ad889aed0ffa5f885dafb1cb48a5bcd3118d5 /winsup/cygwin | |
parent | 3aaa66f813d099dbb04e637459e168800d231aa3 (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')
-rw-r--r-- | winsup/cygwin/ChangeLog | 6 | ||||
-rw-r--r-- | 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 <bill@troyxcd.com> + + * 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 <corinna@vinschen.de> * 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; } |