summaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2014-10-31 12:52:23 +0100
committerGravatar Nikias Bassen2014-11-11 13:35:00 +0100
commit04e07442bbc8a5d8515fa1eea52cb15ebd2cc992 (patch)
treef8045818312a6e07996e1adcada42b7391237973 /src/utils.c
parent50cb34766753f9ad6a046bdc3e1fa1f1a1aacc73 (diff)
downloadusbmuxd-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.c18
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 @@
28#include <string.h> 28#include <string.h>
29#include <stdio.h> 29#include <stdio.h>
30#include <stdarg.h> 30#include <stdarg.h>
31#include <time.h>
31#include <sys/time.h> 32#include <sys/time.h>
32 33
33#include "utils.h" 34#include "utils.h"
@@ -298,15 +299,26 @@ int plist_write_to_filename(plist_t plist, const char *filename, enum plist_form
298 return 1; 299 return 1;
299} 300}
300 301
302void get_tick_count(struct timeval * tv)
303{
304 struct timespec ts;
305 if(0 == clock_gettime(CLOCK_MONOTONIC, &ts)) {
306 tv->tv_sec = ts.tv_sec;
307 tv->tv_usec = ts.tv_nsec / 1000;
308 } else {
309 gettimeofday(tv, NULL);
310 }
311}
312
301/** 313/**
302 * Get number of milliseconds since the epoch. 314 * Get number of milliseconds since the epoch.
303 */ 315 */
304uint64_t mstime64(void) 316uint64_t mstime64(void)
305{ 317{
306 struct timeval tv; 318 struct timeval tv;
307 gettimeofday(&tv, NULL); 319 get_tick_count(&tv);
308 320
309 // Careful, avoid overflow on 32 bit systems 321 // Careful, avoid overflow on 32 bit systems
310 // time_t could be 4 bytes 322 // time_t could be 4 bytes
311 return ((long long)tv.tv_sec) * 1000LL + ((long long)tv.tv_usec) / 1000LL; 323 return ((long long)tv.tv_sec) * 1000LL + ((long long)tv.tv_usec) / 1000LL;
312} 324}