Kevyn-Alexandre Paré wrote:
> 3- In the callback I need to know what the FD is referring to and
> take action, ex: data is ready to be read for the FD of bulk
> transfer.

This is a misunderstanding of USB. Data never becomes available.
The application asks the device to send data, when the application
knows that data is supposed to be available in the device. The device
sends data only when an application asks. The device has no way to
signal that data is available or not available until the application
asks for data.

The libusb API deals with synchronous or asynchronous transfers. The
former block until completion or specified timeout, the latter happen
in the background and the specified callback is called on completion
or on error.

In order to make this work an application must make a small effort to
drive libusb event handling. To run on Windows, there is only one
choice; create a thread which does nothing other than calling
libusb_handle_events_completed() in a loop until there are no more
libusb events to handle (e.g. until your application is exiting).
If Windows is not important then getting the list of fd:s is also an
alternative. When there is an event on any of the fd:s from libusb
then libusb_handle_events() is called to process those events.


> A A Proposition could be that libusb support nice API to
> distinguish them??:

No, the fd:s from libusb are opaque. If something happens on any of
them then libusb is called to take care of the event.


> Otherwise I will please to push a tested patch.

Change your program around a little to use libusb the right way.


It's a common misunderstanding that devices can communicate with the
application without them being asked to transfer any data.

If you want to study USB communication more in depth I recommend
spending a few days with chapter 5, 8, and 9 in the USB 2.0 spec:
http://www.usb.org/developers/docs/usb_20_101111.zip


//Peter

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to