public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: serial: select: call ClearCommError prior to calling WaitCommEvent
@ 2020-03-26 11:26 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2020-03-26 11:26 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a1f0585454ea60f9e10be1f0cdcc7c0c1ceb2d0e
commit a1f0585454ea60f9e10be1f0cdcc7c0c1ceb2d0e
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Mon Mar 23 17:23:19 2020 +0100
Cygwin: serial: select: call ClearCommError prior to calling WaitCommEvent
This (hopefully) eliminates a race condition
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/select.cc | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 07e0d82fb..b933a8ca9 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -1502,6 +1502,9 @@ verify_serial (select_record *me, fd_set *rfds, fd_set *wfds, fd_set *efds)
select_record *
fhandler_serial::select_read (select_stuff *ss)
{
+ COMSTAT st;
+ DWORD io_err;
+
select_record *s = ss->start.next;
s->startup = no_startup;
@@ -1512,18 +1515,25 @@ fhandler_serial::select_read (select_stuff *ss)
s->read_ready = false;
/* This is apparently necessary for the com0com driver.
See: http://cygwin.com/ml/cygwin/2009-01/msg00667.html */
+ ResetEvent (io_status.hEvent);
SetCommMask (get_handle_cyg (), 0);
SetCommMask (get_handle_cyg (), EV_RXCHAR);
- ResetEvent (io_status.hEvent);
- if (!WaitCommEvent (get_handle_cyg (), &event, &io_status))
+ if (ClearCommError (get_handle_cyg (), &io_err, &st) && st.cbInQue)
{
- if (GetLastError () == ERROR_IO_PENDING)
- s->h = io_status.hEvent;
- else
- select_printf ("WaitCommEvent %E");
+ s->read_ready = true;
+ return s;
}
- else
- s->read_ready = true;
+ 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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-03-26 11:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-26 11:26 [newlib-cygwin] Cygwin: serial: select: call ClearCommError prior to calling WaitCommEvent Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).