Core: Handle >= 1 second transfer timeout in libusb_submit_transfer()
authorPeter Stuge <peter@stuge.se>
Wed, 22 Aug 2012 08:32:10 +0000 (01:32 -0700)
committerPete Batard <pete@akeo.ie>
Wed, 22 Aug 2012 21:09:52 +0000 (22:09 +0100)
* Comparisons between tv_nsec and 1 sec should be >= rather than >,
  as we can end up in situations where tv_nsec is exactly 1000000000,
  which calls such as timerfd_create() do not accept.
* Issue reported by Sebastian K. See:
  https://sourceforge.net/mailarchive/message.php?msg_id=29706972

libusb/io.c
libusb/version_nano.h

index 902be15..8a8bc67 100644 (file)
@@ -1141,7 +1141,7 @@ static int calculate_timeout(struct usbi_transfer *transfer)
        current_time.tv_sec += timeout / 1000;
        current_time.tv_nsec += (timeout % 1000) * 1000000;
 
-       if (current_time.tv_nsec > 1000000000) {
+       while (current_time.tv_nsec >= 1000000000) {
                current_time.tv_nsec -= 1000000000;
                current_time.tv_sec++;
        }
@@ -1204,8 +1204,7 @@ out:
                        USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer)->timeout);
                r = timerfd_settime(ctx->timerfd, TFD_TIMER_ABSTIME, &it, NULL);
                if (r < 0) {
-                       usbi_warn(ctx, "failed to arm first timerfd (errno %d, it_value = %d:%d)",
-                               errno, it.it_value.tv_sec, it.it_value.tv_nsec);
+                       usbi_warn(ctx, "failed to arm first timerfd (errno %d)", errno);
                        r = LIBUSB_ERROR_OTHER;
                }
        }
@@ -1745,7 +1744,7 @@ int API_EXPORTED libusb_wait_for_event(libusb_context *ctx, struct timeval *tv)
 
        timeout.tv_sec += tv->tv_sec;
        timeout.tv_nsec += tv->tv_usec * 1000;
-       if (timeout.tv_nsec > 1000000000) {
+       while (timeout.tv_nsec >= 1000000000) {
                timeout.tv_nsec -= 1000000000;
                timeout.tv_sec++;
        }
index 019705e..ffc2981 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10552
+#define LIBUSB_NANO 10553