core: Correctly report cancellations due to timeouts
authorChris Dickens <christopher.a.dickens@gmail.com>
Mon, 3 Aug 2015 06:26:19 +0000 (23:26 -0700)
committerChris Dickens <christopher.a.dickens@gmail.com>
Wed, 5 Aug 2015 05:53:03 +0000 (22:53 -0700)
Prior to this commit, the handle_timeout() function would always
set the USBI_TRANSFER_TIMED_OUT flag on the transfer. However, in
some cases the actual cancellation of the transfer does not succeed,
perhaps because the transfer had just completed. This would cause
occasional false reporting of LIBUSB_TRANSFER_TIMED_OUT when the
transfer did not in fact timeout. This commit adds a check for
successful cancellation before setting the transfer flag.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/io.c
libusb/version_nano.h

index 2937ad9..420f87a 100644 (file)
@@ -1944,9 +1944,10 @@ static void handle_timeout(struct usbi_transfer *itransfer)
                USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
        int r;
 
-       itransfer->flags |= USBI_TRANSFER_TIMED_OUT;
        r = libusb_cancel_transfer(transfer);
-       if (r < 0)
+       if (r == 0)
+               itransfer->flags |= USBI_TRANSFER_TIMED_OUT;
+       else
                usbi_warn(TRANSFER_CTX(transfer),
                        "async cancel failed %d errno=%d", r, errno);
 }
index bdb6213..7f6727f 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10995
+#define LIBUSB_NANO 10996