linux_usbfs: Deal with receiving POLLERR before all transfers have completed

The linux kernel will set its internal device state to USB_STATE_NOTATTACHED
as soon as it detects the disconnect, and then start a worker thread to
deal with the actual disconnection, kill outstanding urbs, etc.

The usbfs poll implementation will return POLL_ERR as soon as
ps->dev->state == USB_STATE_NOTATTACHED. The kernel will not wakeup
the poll until it is done with processing the disconnection. But if
we happen to call poll() between the state change and the disconnection
being fully processed, we may not be able to reap all outstanding transfers,
even on kernels with the USBFS_CAP_REAP_AFTER_DISCONNECT capability.

This commit deals with this by trying to reap as many transfers as possible
on disconnect on USBFS_CAP_REAP_AFTER_DISCONNECT capable kernels and then
calling usbi_handle_disconnect(handle) to deal with any remaining ones.
On USBFS_CAP_REAP_AFTER_DISCONNECT capable kernels this will be a no-op
unless we hit the race.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2 files changed
tree: 47ee07189a4136faae9a2e91590f922bf29c5fa5
  1. .private/
  2. android/
  3. doc/
  4. examples/
  5. libusb/
  6. msvc/
  7. tests/
  8. Xcode/
  9. .gitattributes
  10. .gitignore
  11. .travis.yml
  12. appveyor.yml
  13. appveyor_cygwin.bat
  14. appveyor_minGW.bat
  15. AUTHORS
  16. autogen.sh
  17. bootstrap.sh
  18. ChangeLog
  19. configure.ac
  20. COPYING
  21. INSTALL
  22. INSTALL_WIN.txt
  23. libusb-1.0.pc.in
  24. Makefile.am
  25. NEWS
  26. PORTING
  27. README.git
  28. README.md
  29. TODO
  30. travis-autogen.sh
README.md

libusb

Build Status Build status Coverity Scan Build Status

libusb is a library for USB device access from Linux, Mac OS X, Windows, OpenBSD/NetBSD and Haiku userspace. It is written in C (Haiku backend in C++) and licensed under the GNU Lesser General Public License version 2.1 or, at your option, any later version (see COPYING).

libusb is abstracted internally in such a way that it can hopefully be ported to other operating systems. Please see the PORTING file for more information.

libusb homepage: http://libusb.info/

Developers will wish to consult the API documentation: http://api.libusb.info

Use the mailing list for questions, comments, etc: http://mailing-list.libusb.info

(Please use the mailing list rather than mailing developers directly)