Fix Win32 event use.
Incorrect use of the Ctrl+C event can lead to busy-waiting in socket and serial port IO.
This commit is contained in:
parent
e9b6a77414
commit
fa75aa0854
|
@ -60,6 +60,10 @@ void ctrlc_raise(void);
|
||||||
* object which becomes signalled when the Ctrl+C event is raised.
|
* object which becomes signalled when the Ctrl+C event is raised.
|
||||||
* Implementations of Windows IO operations should allow operations to
|
* Implementations of Windows IO operations should allow operations to
|
||||||
* be interrupted by the signalling of this object.
|
* be interrupted by the signalling of this object.
|
||||||
|
*
|
||||||
|
* The event can be manually cleared before IO operations, but this
|
||||||
|
* doesn't clear the recorded Ctrl+C event. If the event is manually
|
||||||
|
* cleared, the Ctrl+C event status should be checked *after* doing so.
|
||||||
*/
|
*/
|
||||||
HANDLE ctrlc_win32_event(void);
|
HANDLE ctrlc_win32_event(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,6 +37,11 @@ static void sockets_begin(SOCKET s, DWORD event)
|
||||||
|
|
||||||
ioctlsocket(s, FIONBIO, &mode);
|
ioctlsocket(s, FIONBIO, &mode);
|
||||||
WSAEventSelect(s, ctrlc_win32_event(), event);
|
WSAEventSelect(s, ctrlc_win32_event(), event);
|
||||||
|
|
||||||
|
/* We explicitly check for Ctrl+C after resetting the event in
|
||||||
|
* sockets_wait().
|
||||||
|
*/
|
||||||
|
ResetEvent(ctrlc_win32_event());
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sockets_wait(DWORD timeout)
|
static int sockets_wait(DWORD timeout)
|
||||||
|
|
|
@ -256,6 +256,8 @@ static int xfer_wait(sport_t s, LPOVERLAPPED ovl)
|
||||||
{
|
{
|
||||||
DWORD result = 0;
|
DWORD result = 0;
|
||||||
|
|
||||||
|
ResetEvent(ctrlc_win32_event());
|
||||||
|
|
||||||
while (!GetOverlappedResult(s, ovl, &result, FALSE)) {
|
while (!GetOverlappedResult(s, ovl, &result, FALSE)) {
|
||||||
DWORD r;
|
DWORD r;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue