core: introduce grace period

In report mode we break out from select loop immediately after we reach
maximum count of iterations. But we should wait for packets which are still on
the way.

In order to fix the issue we introduce grace period during which we don't send
out more packets but we just wait for responses which might be still on the way.

Resolves: #1009051
This commit is contained in:
Michal Sekletar 2013-10-01 14:29:08 +02:00
parent 7482711a66
commit 2e311d4e97
2 changed files with 77 additions and 0 deletions

View File

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

View File

@ -19,6 +19,7 @@ Patch1: mtr-crash-in-xml-mode.patch
Patch2: mtr-xml-format-fixes.patch Patch2: mtr-xml-format-fixes.patch
Patch3: mtr-default-hostname.patch Patch3: mtr-default-hostname.patch
Patch4: mtr-ipv6-on-ipv4-only.patch Patch4: mtr-ipv6-on-ipv4-only.patch
Patch5: mtr-introduce-grace-period.patch
BuildRequires: ncurses-devel gtk2-devel desktop-file-utils BuildRequires: ncurses-devel gtk2-devel desktop-file-utils
BuildRequires: autoconf automake libtool BuildRequires: autoconf automake libtool
@ -45,6 +46,7 @@ diagnostic tool.
%patch2 -p1 %patch2 -p1
%patch3 -p1 %patch3 -p1
%patch4 -p1 %patch4 -p1
%patch5 -p1
%build %build
export CFLAGS="%{optflags} -fPIE" export CFLAGS="%{optflags} -fPIE"
@ -92,6 +94,7 @@ desktop-file-install \
* Tue Oct 1 2013 Michal Sekletar <msekleta@redhat.com> - 2:0.85-4 * Tue Oct 1 2013 Michal Sekletar <msekleta@redhat.com> - 2:0.85-4
- migrate from consolehelper to policykit (#502750) - migrate from consolehelper to policykit (#502750)
- specfile cleanup - specfile cleanup
- introduce grace period (#1009051)
* Sat Sep 14 2013 Michal Sekletar <msekleta@redhat.com> - 2:0.85-3 * Sat Sep 14 2013 Michal Sekletar <msekleta@redhat.com> - 2:0.85-3
- enable hardened build - enable hardened build