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:
Daniel Beer 2013-02-11 12:49:56 +13:00
parent e9b6a77414
commit fa75aa0854
3 changed files with 11 additions and 0 deletions

View File

@ -60,6 +60,10 @@ void ctrlc_raise(void);
* object which becomes signalled when the Ctrl+C event is raised.
* Implementations of Windows IO operations should allow operations to
* 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);
#endif

View File

@ -37,6 +37,11 @@ static void sockets_begin(SOCKET s, DWORD event)
ioctlsocket(s, FIONBIO, &mode);
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)

View File

@ -256,6 +256,8 @@ static int xfer_wait(sport_t s, LPOVERLAPPED ovl)
{
DWORD result = 0;
ResetEvent(ctrlc_win32_event());
while (!GetOverlappedResult(s, ovl, &result, FALSE)) {
DWORD r;