+ if (due > start_time) {
+ timeout = due - start_time;
+ tv.tv_sec = timeout / G_USEC_PER_SEC;
+ tv.tv_usec = timeout % G_USEC_PER_SEC;
+
+ sr_spew("libusb_handle_events enter: %g ms timeout",
+ 1e-3 * timeout);
+
+ ret = libusb_handle_events_timeout_completed(ctx->libusb_ctx,
+ (ctx->usb_timeout < 0) ? NULL : &tv, NULL);
+ if (ret != 0) {
+ /* Warn but still invoke the callback, to give
+ * the driver a chance to deal with the problem.
+ */
+ sr_warn("Error handling libusb event (%s)",
+ libusb_error_name(ret));
+ }
+ stop_time = g_get_monotonic_time();