diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-08-18 12:25:11 -0700 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-08-18 12:25:11 -0700 |
commit | 6baa3239baf6d2b3a910ba720f63e7edcc0e2740 (patch) | |
tree | f6d932a4ab7a67f1da2c3f0f84fd57badbfb6b24 /libusb | |
parent | 351ad49b3afebeaa25ce471e8e5b82e6b97b5915 (diff) | |
download | libusb-6baa3239baf6d2b3a910ba720f63e7edcc0e2740.tar.gz |
Documentation: Add details regarding timeouts and partial transfer of data
Closes #348
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb')
-rw-r--r-- | libusb/io.c | 35 | ||||
-rw-r--r-- | libusb/sync.c | 4 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
3 files changed, 36 insertions, 5 deletions
diff --git a/libusb/io.c b/libusb/io.c index 18fe755..3b1a513 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -319,9 +319,40 @@ if (r == 0 && actual_length == sizeof(data)) { * Freeing the transfer after it has been cancelled but before cancellation * has completed will result in undefined behaviour. * + * \attention * When a transfer is cancelled, some of the data may have been transferred. - * libusb will communicate this to you in the transfer callback. Do not assume - * that no data was transferred. + * libusb will communicate this to you in the transfer callback. + * <b>Do not assume that no data was transferred.</b> + * + * \section asyncpartial Partial data transfer resulting from cancellation + * + * As noted above, some of the data may have been transferred at the time a + * transfer is cancelled. It is helpful to see how this is possible if you + * consider a bulk transfer to an endpoint with a packet size of 64 bytes. + * Supposing you submit a 512-byte transfer to this endpoint, the operating + * system will divide this transfer up into 8 separate 64-byte frames that the + * host controller will schedule for the device to transfer data. If this + * transfer is cancelled while the device is transferring data, a subset of + * these frames may be descheduled from the host controller before the device + * has the opportunity to finish transferring data to the host. + * + * What your application should do with a partial data transfer is a policy + * decision; there is no single answer that satisfies the needs of every + * application. The data that was successfully transferred should be + * considered entirely valid, but your application must decide what to do with + * the remaining data that was not transferred. Some possible actions to take + * are: + * - Resubmit another transfer for the remaining data, possibly with a shorter + * timeout + * - Discard the partially transferred data and report an error + * + * \section asynctimeout Timeouts + * + * When a transfer times out, libusb internally notes this and attempts to + * cancel the transfer. As noted in \ref asyncpartial "above", it is possible + * that some of the data may actually have been transferred. Your application + * should <b>always</b> check how much data was actually transferred once the + * transfer completes and act accordingly. * * \section bulk_overflows Overflows on device-to-host bulk/interrupt endpoints * diff --git a/libusb/sync.c b/libusb/sync.c index 9ec279f..95be3d9 100644 --- a/libusb/sync.c +++ b/libusb/sync.c @@ -243,7 +243,7 @@ static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle, * underlying O/S requirements, meaning that the timeout may expire after * the first few chunks have completed. libusb is careful not to lose any data * that may have been transferred; do not assume that timeout conditions - * indicate a complete lack of I/O. + * indicate a complete lack of I/O. See \ref asynctimeout for more details. * * \param dev_handle a handle for the device to communicate with * \param endpoint the address of a valid endpoint to communicate with @@ -296,7 +296,7 @@ int API_EXPORTED libusb_bulk_transfer(libusb_device_handle *dev_handle, * underlying O/S requirements, meaning that the timeout may expire after * the first few chunks have completed. libusb is careful not to lose any data * that may have been transferred; do not assume that timeout conditions - * indicate a complete lack of I/O. + * indicate a complete lack of I/O. See \ref asynctimeout for more details. * * The default endpoint bInterval value is used as the polling interval. * diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 0c22d52..7636904 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11541 +#define LIBUSB_NANO 11542 |