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