From: Guus Sliepen Date: Sun, 5 Apr 2020 23:41:14 +0000 (+0200) Subject: Fix RTT measurement. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=9470c449236afef22210803b359fe44d74e32636;p=utcp Fix RTT measurement. Commit 723d8c8b2d96834135f00c0ac4147282e1f0cc2c introduced a bug where we fail to subtract two timespecs correctly, resulting in incorrect RTT values. --- diff --git a/utcp.c b/utcp.c index 383e27f..10d026e 100644 --- a/utcp.c +++ b/utcp.c @@ -61,8 +61,7 @@ static void timespec_sub(const struct timespec *a, const struct timespec *b, str } static int32_t timespec_diff_usec(const struct timespec *a, const struct timespec *b) { - int64_t diff = (a->tv_sec - b->tv_sec) * 1000000000 + a->tv_sec - b->tv_sec; - return diff / 1000; + return (a->tv_sec - b->tv_sec) * 1000000 + (a->tv_nsec - b->tv_nsec) / 1000; } static bool timespec_lt(const struct timespec *a, const struct timespec *b) {