Blame SOURCES/mtr-introduce-grace-period.patch

e38f15
From 6ce1601b27fdd95b44ed65d7fd83604860276d63 Mon Sep 17 00:00:00 2001
e38f15
From: Michal Sekletar <sekletar.m@gmail.com>
e38f15
Date: Tue, 17 Sep 2013 16:11:20 +0200
e38f15
Subject: [PATCH] core: introduce grace period
e38f15
e38f15
In report mode we break out from select loop immediately after we reach
e38f15
maximum count of iterations. But we should wait for packets which are still on
e38f15
the way.
e38f15
e38f15
In order to fix the issue we introduce grace period during which we don't send
e38f15
out more packets but we just wait for responses which might be still on the way.
e38f15
e38f15
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1009051
e38f15
---
e38f15
 select.c | 26 +++++++++++++++++++++++---
e38f15
 1 file changed, 23 insertions(+), 3 deletions(-)
e38f15
e38f15
diff --git a/select.c b/select.c
e38f15
index 29088fd..31bfd5f 100644
e38f15
--- a/select.c
e38f15
+++ b/select.c
e38f15
@@ -45,6 +45,8 @@ static struct timeval intervaltime;
e38f15
 int display_offset = 0;
e38f15
 
e38f15
 
e38f15
+#define GRACETIME (5 * 1000*1000)
e38f15
+
e38f15
 void select_loop(void) {
e38f15
   fd_set readfd;
e38f15
   fd_set writefd;
e38f15
@@ -57,8 +59,12 @@ void select_loop(void) {
e38f15
   int NumPing = 0;
e38f15
   int paused = 0;
e38f15
   struct timeval lasttime, thistime, selecttime;
e38f15
+  struct timeval startgrace;
e38f15
   int dt;
e38f15
   int rv; 
e38f15
+  int graceperiod = 0;
e38f15
+
e38f15
+  memset(&startgrace, 0, sizeof(startgrace));
e38f15
 
e38f15
   gettimeofday(&lasttime, NULL);
e38f15
 
e38f15
@@ -124,10 +130,24 @@ void select_loop(void) {
e38f15
 	   (thistime.tv_sec == lasttime.tv_sec + intervaltime.tv_sec &&
e38f15
 	    thistime.tv_usec >= lasttime.tv_usec + intervaltime.tv_usec)) {
e38f15
 	  lasttime = thistime;
e38f15
-	  if(NumPing >= MaxPing && (!Interactive || ForceMaxPing))
e38f15
+
e38f15
+	  if (!graceperiod) {
e38f15
+	    if (NumPing >= MaxPing && (!Interactive || ForceMaxPing)) {
e38f15
+	      graceperiod = 1;
e38f15
+	      startgrace = thistime;
e38f15
+	    }
e38f15
+
e38f15
+	    /* do not send out batch when we've already initiated grace period */
e38f15
+	    if (!graceperiod && net_send_batch())
e38f15
+	      NumPing++;
e38f15
+	  }
e38f15
+	}
e38f15
+
e38f15
+	if (graceperiod) {
e38f15
+	  dt = (thistime.tv_usec - startgrace.tv_usec) +
e38f15
+		    1000000 * (thistime.tv_sec - startgrace.tv_sec);
e38f15
+	  if (dt > GRACETIME)
e38f15
 	    return;
e38f15
-	  if (net_send_batch())
e38f15
-	    NumPing++;
e38f15
 	}
e38f15
 
e38f15
 	selecttime.tv_usec = (thistime.tv_usec - lasttime.tv_usec);
e38f15
-- 
e38f15
1.8.3.1
e38f15