From f4586570acba4a02750718caa4482d9034479397 Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 7 Sep 2013 15:43:17 -0400 Subject: [PATCH] Use SetEvent instead of CancelIoEx for XP compatibility. --- Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp index 206c11ab64..91bd1bec6c 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp @@ -560,7 +560,7 @@ bool Wiimote::IsConnected() const void _IOWakeup(HANDLE &dev_handle, OVERLAPPED &hid_overlap_read) { - CancelIoEx(dev_handle, &hid_overlap_read); + SetEvent(hid_overlap_read.hEvent); } // positive = read packet @@ -582,26 +582,22 @@ int _IORead(HANDLE &dev_handle, OVERLAPPED &hid_overlap_read, u8* buf, int index if (ERROR_IO_PENDING == read_err) { auto const wait_result = WaitForSingleObject(hid_overlap_read.hEvent, INFINITE); - if (WAIT_TIMEOUT == wait_result) - { - CancelIo(dev_handle); - } - else if (WAIT_FAILED == wait_result) + + // In case the event was signalled by _IOWakeup before the read completed, cancel it. + CancelIo(dev_handle); + + if (WAIT_FAILED == wait_result) { WARN_LOG(WIIMOTE, "A wait error occurred on reading from Wiimote %i.", index + 1); - CancelIo(dev_handle); } - if (!GetOverlappedResult(dev_handle, &hid_overlap_read, &bytes, TRUE)) + if (!GetOverlappedResult(dev_handle, &hid_overlap_read, &bytes, FALSE)) { auto const overlapped_err = GetLastError(); if (ERROR_OPERATION_ABORTED == overlapped_err) { - /* - if (buf[1] != 0) - WARN_LOG(WIIMOTE, "Packet ignored. This may indicate a problem."); - */ + // It was. return -1; }