[prev in list] [next in list] [prev in thread] [next in thread] 

List:       iptraf-ng
Subject:    [PATCH 10/12] packet_size_breakdown(): refactor various time computing
From:       Vitezslav Samel <vitezslav () samel ! cz>
Date:       2014-06-12 9:40:10
Message-ID: 1402566012-8915-11-git-send-email-vitezslav () samel ! cz
[Download RAW message or body]

Signed-off-by: Vitezslav Samel <vitezslav@samel.cz>
---
 src/pktsize.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/pktsize.c b/src/pktsize.c
index 0fc563c..9d699b9 100644
--- a/src/pktsize.c
+++ b/src/pktsize.c
@@ -270,8 +270,14 @@ void packet_size_breakdown(char *ifname, time_t facilitytime)
 	struct timeval last_time = now;
 	struct timeval last_update = now;
 
-	time_t starttime, startlog;
-	starttime = startlog = now.tv_sec;
+	time_t starttime = now.tv_sec;
+	time_t endtime = INT_MAX;
+	if (facilitytime != 0)
+		endtime = now.tv_sec + facilitytime * 60;
+
+	time_t log_next = INT_MAX;
+	if (logging)
+		log_next = now.tv_sec + options.logspan;
 
 	do {
 		gettimeofday(&now, NULL);
@@ -282,17 +288,14 @@ void packet_size_breakdown(char *ifname, time_t facilitytime)
 			dropped += packet_get_dropped(fd);
 			print_packet_drops(dropped, table.borderwin, 49);
 
-			if (logging) {
+			if (logging && (now.tv_sec > log_next)) {
 				check_rotate_flag(&logfile);
-				if ((now.tv_sec - startlog) >= options.logspan) {
-					write_size_log(&table, now.tv_sec - starttime,
-						       ifname, logfile);
-					startlog = now.tv_sec;
-				}
+				write_size_log(&table, now.tv_sec - starttime,
+					       ifname, logfile);
+				log_next = now.tv_sec + options.logspan;
 			}
 
-			if ((facilitytime != 0)
-			    && (((now.tv_sec - starttime) / 60) >= facilitytime))
+			if (now.tv_sec > endtime)
 				exitloop = 1;
 
 			last_time = now;
-- 
1.9.1

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic