diff options
| author | 2014-10-31 12:52:23 +0100 | |
|---|---|---|
| committer | 2014-11-11 13:35:00 +0100 | |
| commit | 04e07442bbc8a5d8515fa1eea52cb15ebd2cc992 (patch) | |
| tree | f8045818312a6e07996e1adcada42b7391237973 /src/usb-linux.c | |
| parent | 50cb34766753f9ad6a046bdc3e1fa1f1a1aacc73 (diff) | |
| download | usbmuxd-04e07442bbc8a5d8515fa1eea52cb15ebd2cc992.tar.gz usbmuxd-04e07442bbc8a5d8515fa1eea52cb15ebd2cc992.tar.bz2 | |
Use new get_tick_count() to avoid timing issues on packets
Diffstat (limited to 'src/usb-linux.c')
| -rw-r--r-- | src/usb-linux.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/usb-linux.c b/src/usb-linux.c index 751b6ed..8acbace 100644 --- a/src/usb-linux.c +++ b/src/usb-linux.c | |||
| @@ -34,6 +34,7 @@ | |||
| 34 | #include "usb.h" | 34 | #include "usb.h" |
| 35 | #include "log.h" | 35 | #include "log.h" |
| 36 | #include "device.h" | 36 | #include "device.h" |
| 37 | #include "utils.h" | ||
| 37 | 38 | ||
| 38 | // interval for device connection/disconnection polling, in milliseconds | 39 | // interval for device connection/disconnection polling, in milliseconds |
| 39 | // we need this because there is currently no asynchronous device discovery mechanism in libusb | 40 | // we need this because there is currently no asynchronous device discovery mechanism in libusb |
| @@ -266,7 +267,7 @@ int usb_discover(void) | |||
| 266 | usbmuxd_log(LL_FATAL, "Too many errors getting device list"); | 267 | usbmuxd_log(LL_FATAL, "Too many errors getting device list"); |
| 267 | return cnt; | 268 | return cnt; |
| 268 | } else { | 269 | } else { |
| 269 | gettimeofday(&next_dev_poll_time, NULL); | 270 | get_tick_count(&next_dev_poll_time); |
| 270 | next_dev_poll_time.tv_usec += DEVICE_POLL_TIME * 1000; | 271 | next_dev_poll_time.tv_usec += DEVICE_POLL_TIME * 1000; |
| 271 | next_dev_poll_time.tv_sec += next_dev_poll_time.tv_usec / 1000000; | 272 | next_dev_poll_time.tv_sec += next_dev_poll_time.tv_usec / 1000000; |
| 272 | next_dev_poll_time.tv_usec = next_dev_poll_time.tv_usec % 1000000; | 273 | next_dev_poll_time.tv_usec = next_dev_poll_time.tv_usec % 1000000; |
| @@ -477,7 +478,7 @@ int usb_discover(void) | |||
| 477 | 478 | ||
| 478 | libusb_free_device_list(devs, 1); | 479 | libusb_free_device_list(devs, 1); |
| 479 | 480 | ||
| 480 | gettimeofday(&next_dev_poll_time, NULL); | 481 | get_tick_count(&next_dev_poll_time); |
| 481 | next_dev_poll_time.tv_usec += DEVICE_POLL_TIME * 1000; | 482 | next_dev_poll_time.tv_usec += DEVICE_POLL_TIME * 1000; |
| 482 | next_dev_poll_time.tv_sec += next_dev_poll_time.tv_usec / 1000000; | 483 | next_dev_poll_time.tv_sec += next_dev_poll_time.tv_usec / 1000000; |
| 483 | next_dev_poll_time.tv_usec = next_dev_poll_time.tv_usec % 1000000; | 484 | next_dev_poll_time.tv_usec = next_dev_poll_time.tv_usec % 1000000; |
| @@ -538,7 +539,7 @@ static int dev_poll_remain_ms(void) | |||
| 538 | struct timeval tv; | 539 | struct timeval tv; |
| 539 | if(!device_polling) | 540 | if(!device_polling) |
| 540 | return 100000; // devices will never be polled if this is > 0 | 541 | return 100000; // devices will never be polled if this is > 0 |
| 541 | gettimeofday(&tv, NULL); | 542 | get_tick_count(&tv); |
| 542 | msecs = (next_dev_poll_time.tv_sec - tv.tv_sec) * 1000; | 543 | msecs = (next_dev_poll_time.tv_sec - tv.tv_sec) * 1000; |
| 543 | msecs += (next_dev_poll_time.tv_usec - tv.tv_usec) / 1000; | 544 | msecs += (next_dev_poll_time.tv_usec - tv.tv_usec) / 1000; |
| 544 | if(msecs < 0) | 545 | if(msecs < 0) |
| @@ -595,7 +596,7 @@ int usb_process_timeout(int msec) | |||
| 595 | { | 596 | { |
| 596 | int res; | 597 | int res; |
| 597 | struct timeval tleft, tcur, tfin; | 598 | struct timeval tleft, tcur, tfin; |
| 598 | gettimeofday(&tcur, NULL); | 599 | get_tick_count(&tcur); |
| 599 | tfin.tv_sec = tcur.tv_sec + (msec / 1000); | 600 | tfin.tv_sec = tcur.tv_sec + (msec / 1000); |
| 600 | tfin.tv_usec = tcur.tv_usec + (msec % 1000) * 1000; | 601 | tfin.tv_usec = tcur.tv_usec + (msec % 1000) * 1000; |
| 601 | tfin.tv_sec += tfin.tv_usec / 1000000; | 602 | tfin.tv_sec += tfin.tv_usec / 1000000; |
| @@ -614,7 +615,7 @@ int usb_process_timeout(int msec) | |||
| 614 | } | 615 | } |
| 615 | // reap devices marked dead due to an RX error | 616 | // reap devices marked dead due to an RX error |
| 616 | reap_dead_devices(); | 617 | reap_dead_devices(); |
| 617 | gettimeofday(&tcur, NULL); | 618 | get_tick_count(&tcur); |
| 618 | } | 619 | } |
| 619 | return 0; | 620 | return 0; |
| 620 | } | 621 | } |
