Cygwin: serial: select: call ClearCommError prior to calling WaitCommEvent
This (hopefully) eliminates a race condition Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
3a74630f75
commit
a1f0585454
|
@ -1502,6 +1502,9 @@ verify_serial (select_record *me, fd_set *rfds, fd_set *wfds, fd_set *efds)
|
||||||
select_record *
|
select_record *
|
||||||
fhandler_serial::select_read (select_stuff *ss)
|
fhandler_serial::select_read (select_stuff *ss)
|
||||||
{
|
{
|
||||||
|
COMSTAT st;
|
||||||
|
DWORD io_err;
|
||||||
|
|
||||||
select_record *s = ss->start.next;
|
select_record *s = ss->start.next;
|
||||||
|
|
||||||
s->startup = no_startup;
|
s->startup = no_startup;
|
||||||
|
@ -1512,19 +1515,26 @@ fhandler_serial::select_read (select_stuff *ss)
|
||||||
s->read_ready = false;
|
s->read_ready = false;
|
||||||
/* This is apparently necessary for the com0com driver.
|
/* This is apparently necessary for the com0com driver.
|
||||||
See: http://cygwin.com/ml/cygwin/2009-01/msg00667.html */
|
See: http://cygwin.com/ml/cygwin/2009-01/msg00667.html */
|
||||||
|
ResetEvent (io_status.hEvent);
|
||||||
SetCommMask (get_handle_cyg (), 0);
|
SetCommMask (get_handle_cyg (), 0);
|
||||||
SetCommMask (get_handle_cyg (), EV_RXCHAR);
|
SetCommMask (get_handle_cyg (), EV_RXCHAR);
|
||||||
ResetEvent (io_status.hEvent);
|
if (ClearCommError (get_handle_cyg (), &io_err, &st) && st.cbInQue)
|
||||||
if (!WaitCommEvent (get_handle_cyg (), &event, &io_status))
|
|
||||||
{
|
{
|
||||||
if (GetLastError () == ERROR_IO_PENDING)
|
|
||||||
s->h = io_status.hEvent;
|
|
||||||
else
|
|
||||||
select_printf ("WaitCommEvent %E");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
s->read_ready = true;
|
s->read_ready = true;
|
||||||
return s;
|
return s;
|
||||||
|
}
|
||||||
|
if (WaitCommEvent (get_handle_cyg (), &event, &io_status))
|
||||||
|
{
|
||||||
|
s->read_ready = true;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
if (GetLastError () == ERROR_IO_PENDING)
|
||||||
|
{
|
||||||
|
s->h = io_status.hEvent;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
select_printf ("WaitCommEvent %E");
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
select_record *
|
select_record *
|
||||||
|
|
Loading…
Reference in New Issue