Add USBI_TRANSFER_CANCELLING and _DEVICE_DISAPPEARED status flags
authorVitali Lovich <vlovich@aliph.com>
Thu, 17 Mar 2011 02:48:35 +0000 (19:48 -0700)
committerPeter Stuge <peter@stuge.se>
Sun, 24 Jul 2011 20:29:09 +0000 (22:29 +0200)
The flags are used to indicate if a cancellation has started, and if
a cancellation has failed because the device is no longer available.
References #82.

libusb/io.c
libusb/libusbi.h

index 56c1d34..3ef422a 100644 (file)
@@ -1309,9 +1309,16 @@ int API_EXPORTED libusb_cancel_transfer(struct libusb_transfer *transfer)
        usbi_dbg("");
        usbi_mutex_lock(&itransfer->lock);
        r = usbi_backend->cancel_transfer(itransfer);
-       if (r < 0)
+       if (r < 0) {
                usbi_err(TRANSFER_CTX(transfer),
                        "cancel transfer failed error %d", r);
+
+               if (r == LIBUSB_ERROR_NO_DEVICE)
+                       itransfer->flags |= USBI_TRANSFER_DEVICE_DISAPPEARED;
+       }
+
+       itransfer->flags |= USBI_TRANSFER_CANCELLING;
+
        usbi_mutex_unlock(&itransfer->lock);
        return r;
 }
index 2046623..1ea7f26 100644 (file)
@@ -333,6 +333,12 @@ enum usbi_transfer_flags {
 
        /* Set by backend submit_transfer() if the OS handles timeout */
        USBI_TRANSFER_OS_HANDLES_TIMEOUT = 1 << 1,
+
+       /* Cancellation was requested via libusb_cancel_transfer() */
+       USBI_TRANSFER_CANCELLING = 1 << 2,
+
+       /* Operation on the transfer failed because the device disappeared */
+       USBI_TRANSFER_DEVICE_DISAPPEARED = 1 << 3,
 };
 
 #define __USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer) \