summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Stewart <patrick@rfcreations.com>2018-01-31 15:18:06 +0000
committerChris Dickens <christopher.a.dickens@gmail.com>2018-02-23 23:55:52 -0800
commit32617df7143c58a204e130f6c65f5226a2ea046e (patch)
tree24ace4c2e35293f5447e509beb53193674b5c043
parentcd7aeec8e73768f6091cec9c0d097adbc139b402 (diff)
downloadlibusb-32617df7143c58a204e130f6c65f5226a2ea046e.tar.gz
Windows: Fix race condition between submit and handle events
Check the event object for completion in poll instead of using HasOverlappedIoCompleted. When we submit a transfer on Windows the fd is added to the poll list before the read/write begins, so HasOverlappedIoCompleted can be called before overlapped.Internal is set to ERROR_IO_PENDING if events are being being handled concurrently, so the fd will be marked as completed before it has actually started. [dickens] Instead of replacing HasOverlappedIoCompleted, supplement it so that it can provide a fast path to avoid WaitForSingleObject() in the general case Closes #386, Closes #387 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--libusb/os/poll_windows.c4
-rw-r--r--libusb/version_nano.h2
2 files changed, 3 insertions, 3 deletions
diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c
index 654965b..bb3d178 100644
--- a/libusb/os/poll_windows.c
+++ b/libusb/os/poll_windows.c
@@ -149,8 +149,8 @@ static int check_pollfds(struct pollfd *fds, unsigned int nfds,
continue;
}
- // The following macro only works if overlapped I/O was reported pending
- if (HasOverlappedIoCompleted(&fd->overlapped)) {
+ if (HasOverlappedIoCompleted(&fd->overlapped)
+ && (WaitForSingleObject(fd->overlapped.hEvent, 0) == WAIT_OBJECT_0)) {
fds[n].revents = fds[n].events;
nready++;
} else if (wait_handles != NULL) {
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index e40a0dd..eb2eab4 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11298
+#define LIBUSB_NANO 11299