diff options
author | 2014-10-31 12:52:23 +0100 | |
---|---|---|
committer | 2014-11-11 13:35:00 +0100 | |
commit | 04e07442bbc8a5d8515fa1eea52cb15ebd2cc992 (patch) | |
tree | f8045818312a6e07996e1adcada42b7391237973 /src/utils.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/utils.c')
-rw-r--r-- | src/utils.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/utils.c b/src/utils.c index 5dd871d..ceb65e1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -28,6 +28,7 @@ #include <string.h> #include <stdio.h> #include <stdarg.h> +#include <time.h> #include <sys/time.h> #include "utils.h" @@ -298,15 +299,26 @@ int plist_write_to_filename(plist_t plist, const char *filename, enum plist_form return 1; } +void get_tick_count(struct timeval * tv) +{ + struct timespec ts; + if(0 == clock_gettime(CLOCK_MONOTONIC, &ts)) { + tv->tv_sec = ts.tv_sec; + tv->tv_usec = ts.tv_nsec / 1000; + } else { + gettimeofday(tv, NULL); + } +} + /** * Get number of milliseconds since the epoch. */ uint64_t mstime64(void) { struct timeval tv; - gettimeofday(&tv, NULL); + get_tick_count(&tv); - // Careful, avoid overflow on 32 bit systems - // time_t could be 4 bytes + // Careful, avoid overflow on 32 bit systems + // time_t could be 4 bytes return ((long long)tv.tv_sec) * 1000LL + ((long long)tv.tv_usec) / 1000LL; } |