diff options
author | Christopher Faylor <me@cgf.cx> | 2001-01-30 01:52:29 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2001-01-30 01:52:29 +0000 |
commit | 747e88d3f6c0a4007dd32b315700246d21e21ecb (patch) | |
tree | f42ad889aed0ffa5f885dafb1cb48a5bcd3118d5 /winsup/cygwin/fhandler_serial.cc | |
parent | 3aaa66f813d099dbb04e637459e168800d231aa3 (diff) | |
download | cygnal-747e88d3f6c0a4007dd32b315700246d21e21ecb.tar.gz cygnal-747e88d3f6c0a4007dd32b315700246d21e21ecb.tar.bz2 cygnal-747e88d3f6c0a4007dd32b315700246d21e21ecb.zip |
* 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.cc | 16 |
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; } |