Peter A. Bigot wrote: > I keep getting close, but haven't conquered the edge cases. > In particular, when things go wrong I can still get hangs or segfaults, > because libusb_submit_transfer() and libusb_cancel_transfer() do not give > reliable information about whether the callback will be subsequently be > called:
The callback will always be called. > even with error returns, sometimes it is and sometimes it isn't. If the callback is not called that is a (severe) bug in the libusb-1.0 implementation you are using. The original author of libusb-1.0, Daniel Drake, made me maintainer when he moved on from libusb.org to work on other things. Meanwhile, the libusb project on SF and github has been taken over by the libusbx developers, who created their hostile fork of libusb because they were frustrated by my development style. My development style is to be correct before anything else. Some of the libusbx developers write really poor code really quickly. Distributions all switched to package the libusbx developers' code, when one of the libusbx developers who works for Red Hat announced that he had switched the Fedora package. I follow the developments and I continue efforts at libusb.org, although no code has entered the git in a long time. I so far haven't seen any issue with a libusb-1.0 implementation causing lost callbacks, and I'd be interested in understanding that problem better, and certainly fixing it if libusb.org code does it. > There may be a way to determine from the specific error value, but that > behavior isn't documented. Without well-defined behavior, I can't tell > when it's safe to release the transfer buffer. It's safe to free the buffer after a sync API transfer returns or at any time after the callback is called for an async API transfer. libusb is done with the transfer when the callback is called, to allow the transfer to be resubmitted by the callback if it wants to. This is by design and I believe documented, but maybe not. > the specific libusb versions I have to deal with. Which are those? I'd appreciate if you give the code on git.libusb.org a go, that's the only code I can recommend as a baseline. There are plenty of things that it doesn't do, which libusbx developers have implemented some way or other, and if it's a good way then they will be included by me too at some point. //Peter
