Vitezslav Samel <vitezslav(a)samel.cz> writes:
The test if we need to update the display is the same in 5 files;
make this a function: code is more readable, code is smaller,
code is (marginally) faster (I eliminated 64-bit multiply).
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/deskman.c | 17 +++++++++++++++++
src/deskman.h | 1 +
src/detstats.c | 15 +++++----------
src/hostmon.c | 15 +++++----------
src/ifstats.c | 15 +++++----------
src/iptraf-ng-compat.h | 3 +++
src/itrafmon.c | 15 +++++----------
src/options.h | 2 --
src/packet.c | 2 +-
src/pktsize.c | 15 +++++----------
src/serv.c | 15 +++++----------
11 files changed, 52 insertions(+), 63 deletions(-)
diff --git a/src/deskman.c b/src/deskman.c
index 25940dc..e0a76cf 100644
--- a/src/deskman.c
+++ b/src/deskman.c
@@ -14,6 +14,7 @@ deskman.c - desktop management routines
#include "tui/winops.h"
#include "deskman.h"
+#include "options.h"
/* Attribute variables */
@@ -194,6 +195,22 @@ void printlargenum(unsigned long long i, WINDOW * win)
wprintw(win, "%8lluT", i / 1000000000000ULL);
}
+int update_needed(const struct timeval *now, const struct timeval *last)
+{
+ unsigned long msecs = timeval_diff_msec(now, last);
+ if (options.updrate == 0) {
+ if (msecs >= DEFAULT_UPDATE_DELAY)
+ return 1;
+ else
+ return 0;
+ } else {
+ if (msecs >= (options.updrate * 1000UL))
+ return 1;
+ else
+ return 0;
+ }
+}
I'm not sure if that is right name for that function. update_needed
doesn't give me any hit, what will be updated, or will it 'something'
update inside itself.
--
Nikola