Skip to content

Commit

Permalink
use clock_gettime instead of gettimeofday
Browse files Browse the repository at this point in the history
  • Loading branch information
nathhB committed Sep 18, 2023
1 parent f7bbff2 commit 465ac56
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions nbnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
#endif

#ifndef NBNET_WINDOWS
#include <sys/time.h> // gettimeofday
#include <sys/time.h>
#include <time.h>
#endif

#ifndef NBN_Allocator
Expand Down Expand Up @@ -5055,15 +5056,15 @@ static void Endpoint_UpdateTime(NBN_Endpoint *endpoint)
#ifdef NBNET_WINDOWS
endpoint->time = GetTickCount64() / 1000.0;
#else
static struct timeval tp;
static struct timespec tp;

if (gettimeofday(&tp, NULL) < 0)
if (clock_gettime(CLOCK_MONOTONIC_RAW, &tp) < 0)
{
NBN_LogError("gettimeofday() failed");
NBN_Abort();
}

endpoint->time = tp.tv_sec + (tp.tv_usec / (double)1e6);
endpoint->time = tp.tv_sec + (tp.tv_nsec / (double)1e9);
#endif // NBNET_WINDOWS
}

Expand Down

0 comments on commit 465ac56

Please sign in to comment.