This seems to be good for libusb.org as well.
---------- Forwarded message ----------
From: Zoltán Kovács
Date: Mon, Jan 21, 2013 at 1:03 AM
Subject: [Libusbx-devel] libusb_interrupt_transfer does not return in
case of error
I use libusbx on Linux to communicate with a weather station. I use
libusb_interrupt_transfer call to get data from the device. Sometimes
there is a communication error with the device:
[372849.680990] [0000275b] libusbx: error [reap_for_handle] reap
failed error -1 errno=14
[372849.681752] [0000275b] libusbx: error [handle_events] backend
handle_events failed with error -1
[372850.680466] [0000275b] libusbx: warning [handle_timeout] async
cancel failed -5 errno=22
in this case the program does not return from
libusb_interrupt_transfer, so I cannot handle the error in my code. I
made some debugging and I think found a bug in do_sync_bulk_transfer
function: the return value of libusb_cancel_transfer not handled. If
this function returns with error, the while loop never ends.
My proposed fix:
pi@... ~/homectrl/libusbx-1.0.14/libusb $ diff sync_old.c sync.c
< while (!completed)
< if (libusb_handle_events_completed(HANDLE_CTX(dev_handle), &completed) < 0)
> if(libusb_cancel_transfer(transfer) == 0)
> while (!completed)
> if (libusb_handle_events_completed(HANDLE_CTX(dev_handle), &completed) < 0)
the same problem exists in the libusb_control_transfer function, too.
I tested this and seems this solves the problem.
If you agree, please correct the code according to this.