From 532b9ca451311639ca70276fac52c3776c1b2e5b Mon Sep 17 00:00:00 2001 From: lemoer Date: Wed, 18 May 2016 21:32:24 +0200 Subject: [PATCH] pong handler: fix incorrect calculation for rtt Before this fix seconds were treated as milliseconds. Example: A ping of 1.001s resulted in current_rtt = 2 (ms) where a ping of 0.999s resulted in current_rtt = 999 (ms). --- src/protocol_misc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/protocol_misc.c b/src/protocol_misc.c index 7480f4d8..91bb28c0 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -150,12 +150,11 @@ bool pong_h(connection_t *c, const char *request) { logger(DEBUG_ALWAYS, LOG_ERR, "bogus pong received from %s (%s)", c->name, c->hostname); return false; } - /* RTT should be in ms */ - current_rtt = (_now.tv_sec - tv_sec)*1000; - /* Compute diff between usec */ - current_rtt += _now.tv_usec >= tv_usec ? _now.tv_usec - tv_usec : tv_usec - _now.tv_usec; - current_rtt = current_rtt/1000; + /* current_rtt should be in ms */ + current_rtt += (_now.tv_sec - tv_sec) * 1000; + /* Compute diff between usec */ + current_rtt += (_now.tv_usec - tv_usec) / 1000; if (c->edge->avg_rtt == 0) c->edge->avg_rtt = current_rtt;