summaryrefslogtreecommitdiff
path: root/libusb/os/poll_windows.h
Commit message (Collapse)AuthorAgeFilesLines
* windows: remove total fds (256) limitationsFrank Li2019-08-091-2/+0
| | | | | | | | | | | | | | | When queue more usb requests, and more devices working at the same time 256's limitation is easy to reach. This patch remove such limitation of windows version. dymatic allocate map fd_table. each time increase 256 entry if request more fds. Closes #592 Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows: fix return type of usbi_{inc,dec}_fds_ref.Josh Gao2019-07-071-2/+2
| | | | | | | | | These functions were declared as returning int, but failed to actually return anything, and no one was using their return values anyway. Closes #562 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* fix windows crash when multi-thread do sync transferFrank Li2019-04-041-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fun() { libusb_open() ... sync transfer libusb_close() } two thread call fun infininately. to speed up crash, enable application verifier below 20 cycle, assert(fd!=NULL) happen at check_pollfds below 100 cycle, crash at pollable_fd->overlappend in winusb_get_overlapped result with this fix, success fun over 1000 cycles in handle_events usbi_mutex_lock() fds = ctx->pollfds nfds = ctx->pollfds_cnt; usbi_mutex_unclock() usbi_poll() callback. usbi poll is not in mutex. pollfds may be change by usbi_add_pollfd and usbi_remove_pollfd. Although usbi_add_pollfd and usbi_remove_pollfd hold mutex, but usbi_poll and callback is not in protext of mutex. windows use fd as index of fb_table. fb_table may changed by usbi_remove_pollfd. the map between fd and internal file_descriptor may be wrong. this patch added ref count for file_descriptor, only free file_desciptor and remove it from fb_table when ref count is 0. ref count will be increase when fds copy with mutex lock. so fd always index validate file_descriptor. ref count will be descress before return from handle_events. the file_descriptor can be free safely at this time. Closes #521 Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Windows: Enable dynamic selection between WinUSB and UsbDk backendsChris Dickens2018-01-081-15/+0
| | | | | | | | | | | | | This commit unifies the two Windows backends into a single project and enables the user to switch to the UsbDk backend, if available, using the libusb_set_option() function. All contexts will use the WinUSB backend by default for backwards compatibility. With this change, the UsbDk-specific projects are no longer required. Closes #309 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Rework poll() emulation to a much simpler and effective designChris Dickens2018-01-061-28/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* windows: fix USB 3.0 speed detection on Windows 8 or laterPete Batard2014-05-181-6/+12
| | | | | | * ...since Microsoft broke IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX between Windows 7 and Windows 8 * Also improve Windows version detection and reporting * Closes #10
* Windows: Correctly clear backend transfer private informationToby Gray2013-04-111-1/+1
| | | | | | | | | | | | | | | | | | | | | * Without this fix if a transfer is reused then there is a period of time between it being adding to the flying transfer list and submitted where the fd value will be the old fd value. * If this occurs at the same time as all of the following conditions then the incorrect transfer will be handled as having completed: * The old fd value in the reused transfer has been recycled for a currently pending transfer. * This other pending transfer has a later timeout than the reused transfer (so therefore comes later in the flying transfer list). * The other pending transfer completes, therefore signalling the fd. As the flying transfer list is examined in order when handling events, the resubmitted transfer with the old fd value will be considered as completed. This will generally cause a NULL pointer dereference as the OVERLAPPED structure was already freed. Also see: http://libusbx.1081486.n5.nabble.com/Libusbx-devel-PATCH-Fix-NULL-pointer-dereference-in-Windows-and-WinCE-backends-when-reusing-transfers-tt1041.html
* WinCE: Post integration cleanupPete Batard2013-03-031-1/+2
| | | | | | * Update copyrights and switch to UTF-8 everywhere * Add SleepEx() to missing.h, and move include to libusbi.h * Remove ifdef for GetSystemTimeAsFileTime()
* Windows: Simplify poll_windows and add provisions for WinCEToby Gray2013-01-231-1/+11
| | | | | * Because poll_windows now requires struct usbi_transfer to be defined, it's inclusion in libusbi.h had to be moved down.
* Misc: Ensure all sources are UTF-8Pete Batard2012-05-231-1/+1
| | | | * Also remove extra lines at the end of samples
* Windows: Remove #define options and use same set of defaultsPete Batard2012-04-111-5/+0
| | | | | | * The DYNAMIC_FDS, AUTO_CLAIM and FORCE_INSTANT_TIMEOUTS options were introduced for development/testing and don't appear to be used by the Windows backend users => remove them.
* Windows: misc improvementsPete Batard2012-04-101-1/+1
| | | | | | * prefer calloc over malloc * silence VS2010 intellisense warnings on mem allocation * other minor fixes and formatting improvements to align with -pbatard
* Misc: Rebrand to libusbxPete Batard2012-04-031-2/+1
| | | | | * Mentions of 'libusb' in doxygen are changed to 'libusbx' * Also update copyright notices and remove unneeded EOF LFs
* Windows: Fix undefined datatype 'LONG_PTR' in MSVC6Pete Batard2012-02-081-1/+1
| | | | | | * issue reported by Elmi Signed-off-by: Michael Plante <michael.plante@gmail.com>
* Windows: Don't leak pipe fdsPete Batard2011-06-131-4/+6
| | | | | | | | | | | use _open() and _close() rather than _open_osfhandle() and CloseHandle() * use of CloseHandle() prevented the pipe fds from being relinquished on libusb_exit() * leaked fds could lead to the OS running out of new fds and LIBUSB_ERROR_NO_MEM being returned as a result * using _open() avoids _open_osfhandle() redef for cygwin * issue reported by Stephano Antonelli
* configure.ac: Check for poll.h, and for nfds_t on DarwinPeter Stuge2011-06-131-2/+0
| | | | | | | | | | | On Linux, assume nfds_t is always available. On Darwin, fall back to unsigned int when poll() exists but there is no nfds_t, such as on Mac OS X before 10.4. On Windows (both MinGW and Cygwin), always use unsigned int instead of nfds_t, and don't check for poll.h because we use our own poll() implementation.
* Add Windows supportPete Batard2010-07-271-0/+120
Via Cygwin/MinGW, libusb now has windows support. Thanks to contributors: Michael Plante, Orin Eman, Peter Stuge, Stephan Meyer, Xiaofan Chen.