summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Goodney <agoodney@yahoo.com>2021-12-27 20:34:05 -0800
committerNathan Hjelm <hjelmn@google.com>2022-01-18 15:32:24 -0700
commitc1ed5895438f2ae3767162f74388b09a16ab0800 (patch)
tree70f824305d29dab77b0cee0dc027701f257815df
parentf2b218b61867f27568ba74fa38e156e5f55ed825 (diff)
downloadlibusb-c1ed5895438f2ae3767162f74388b09a16ab0800.tar.gz
The current code for calculating the timeout in darwin_reenumerate_device_timeout() doesn't calculate elapsed microseconds, it counts the number of times the loop runs.
This results in very long timeouts. This PR uses clock_gettime(CLOCK_MONOTONIC, ...) to calculate the elapsed time Closes #1035 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
-rw-r--r--libusb/os/darwin_usb.c12
-rw-r--r--libusb/version_nano.h2
2 files changed, 10 insertions, 4 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index c64ecd1..903422c 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -1753,7 +1753,6 @@ static int darwin_reenumerate_device (struct libusb_device_handle *dev_handle, b
IOUSBConfigurationDescriptor *cached_configurations;
IOReturn kresult;
UInt8 i;
- UInt32 time;
struct libusb_context *ctx = HANDLE_CTX (dev_handle);
@@ -1801,11 +1800,18 @@ static int darwin_reenumerate_device (struct libusb_device_handle *dev_handle, b
usbi_dbg (ctx, "darwin/reenumerate_device: waiting for re-enumeration to complete...");
- time = 0;
+ struct timespec start;
+ clock_gettime(CLOCK_MONOTONIC, &start);
+
while (dpriv->in_reenumerate) {
struct timespec delay = {.tv_sec = 0, .tv_nsec = 1000};
nanosleep (&delay, NULL);
- if (time++ >= DARWIN_REENUMERATE_TIMEOUT_US) {
+
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ UInt32 elapsed = (now.tv_sec - start.tv_sec) * 1000000 + (now.tv_nsec - start.tv_nsec) / 1000;
+
+ if (elapsed >= DARWIN_REENUMERATE_TIMEOUT_US) {
usbi_err (ctx, "darwin/reenumerate_device: timeout waiting for reenumerate");
dpriv->in_reenumerate = false;
return LIBUSB_ERROR_TIMEOUT;
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index b129143..30643ff 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11681
+#define LIBUSB_NANO 11683