* fhandler_serial.cc (raw_write): Use local copy of OVERLAPPED structure

instead of shared structure to fix a race condition between read/write.
This commit is contained in:
Christopher Faylor 2001-01-30 01:52:29 +00:00
parent 3aaa66f813
commit 747e88d3f6
2 changed files with 15 additions and 7 deletions

View File

@ -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

View File

@ -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;
}