Documentation: Add details regarding timeouts and partial transfer of data Closes #348 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
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 @@ * 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 @@ * 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 @@ * 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