Windows: Rework poll() emulation to a much simpler and effective design
authorChris Dickens <christopher.a.dickens@gmail.com>
Sun, 7 Jan 2018 05:43:12 +0000 (21:43 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Sun, 7 Jan 2018 05:43:12 +0000 (21:43 -0800)
commitd0779e93032affec1dcf04a5bba18f3968aa7922
tree2609450edece322a4421764a2d804fa7607a1214
parent0865774fe93b2d0d9729ab23f9dfb10af1433312
Windows: Rework poll() emulation to a much simpler and effective design

The previous poll() implementation worked okay but had some issues. It
was inefficient, had a large footprint, and there were simply some use
cases that didn't work (e.g. a synchronous transfer that completes when
no other event or transfer is pending would not be processed until the
next poll() timeout).

This commit introduces a new, simpler design that simply associates an
OVERLAPPED structure to an integer that acts as a file descriptor. The
poll() emulation now solely cares about the OVERLAPPED structure, not
transfers or HANDLEs or cancelation functions. These details have been
moved up into the higher OS-specific layers.

For Windows NT environments, several deficiencies have been addressed:

1) It was previously possible to successfully submit a transfer but fail
   to add the "file descriptor" to the pollfd set. This was silently
   ignored and would result in the user never seeing the transfer being
   completed.

2) Synchronously completed transfers would previously not be processed
   unless another event (such as a timeout or other transfer completion)
   was processed.

3) Canceling any one transfer on an endpoint would previously result in
   *all* transfers on that endpoint being canceled, due to the use of
   the AbortPipe() function.

This commit addresses all of these issues. In particular, run-time
detection of the CancelIoEx() function will allow the user to cancel a
single outstanding transfer without affecting any others still in
process.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/os/poll_windows.c
libusb/os/poll_windows.h
libusb/os/threads_windows.h
libusb/os/wince_usb.c
libusb/os/windows_nt_common.c
libusb/os/windows_nt_common.h
libusb/os/windows_usbdk.c
libusb/os/windows_winusb.c
libusb/os/windows_winusb.h
libusb/version_nano.h