1 From d0e66e0719ae8eb549f7cc220fdc66575d3db332 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Thu, 29 Mar 2012 17:01:11 +0200
4 Subject: [PATCH 4/4] use monotic clock instead of time of day
6 The time of day might chance e.g. by daylight savings time during the
7 runtime, which causes timers to fire repeatedly for a long time.
9 Contributed by T-Labs, Deutsche Telekom Innovation Laboratories
11 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
14 src/igmpproxy.c | 26 +++++++++++++-------------
15 src/igmpproxy.h | 3 ++-
16 3 files changed, 17 insertions(+), 14 deletions(-)
18 diff --git a/configure.ac b/configure.ac
19 index 85beb08..bd84eba 100644
22 @@ -25,6 +25,8 @@ AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], [], [], [[
23 #include <netinet/in.h>
26 +AC_SEARCH_LIBS([clock_gettime],[rt])
31 diff --git a/src/igmpproxy.c b/src/igmpproxy.c
32 index 35000c7..3a9ccad 100644
35 @@ -234,13 +234,13 @@ void igmpProxyRun() {
39 - struct timeval curtime, lasttime, difftime, tv;
40 + struct timespec curtime, lasttime, difftime, tv;
41 // The timeout is a pointer in order to set it to NULL if nessecary.
42 - struct timeval *timeout = &tv;
43 + struct timespec *timeout = &tv;
45 // Initialize timer vars
46 - difftime.tv_usec = 0;
47 - gettimeofday(&curtime, NULL);
48 + difftime.tv_nsec = 0;
49 + clock_gettime(CLOCK_MONOTONIC, &curtime);
52 // First thing we send a membership query in downstream VIF's...
53 @@ -263,7 +263,7 @@ void igmpProxyRun() {
57 - timeout->tv_usec = 0;
58 + timeout->tv_nsec = 0;
59 timeout->tv_sec = secs;
62 @@ -274,7 +274,7 @@ void igmpProxyRun() {
63 FD_SET( MRouterFD, &ReadFDS );
66 - Rt = select( MaxFD +1, &ReadFDS, NULL, NULL, timeout );
67 + Rt = pselect( MaxFD +1, &ReadFDS, NULL, NULL, timeout, NULL );
69 // log and ignore failures
71 @@ -307,20 +307,20 @@ void igmpProxyRun() {
74 curtime.tv_sec = lasttime.tv_sec + secs;
75 - curtime.tv_usec = lasttime.tv_usec;
76 + curtime.tv_nsec = lasttime.tv_nsec;
77 Rt = -1; /* don't do this next time through the loop */
79 - gettimeofday(&curtime, NULL);
80 + clock_gettime(CLOCK_MONOTONIC, &curtime);
82 difftime.tv_sec = curtime.tv_sec - lasttime.tv_sec;
83 - difftime.tv_usec += curtime.tv_usec - lasttime.tv_usec;
84 - while (difftime.tv_usec > 1000000) {
85 + difftime.tv_nsec += curtime.tv_nsec - lasttime.tv_nsec;
86 + while (difftime.tv_nsec > 1000000000) {
88 - difftime.tv_usec -= 1000000;
89 + difftime.tv_nsec -= 1000000000;
91 - if (difftime.tv_usec < 0) {
92 + if (difftime.tv_nsec < 0) {
94 - difftime.tv_usec += 1000000;
95 + difftime.tv_nsec += 1000000000;
98 if (secs == 0 || difftime.tv_sec > 0)
99 diff --git a/src/igmpproxy.h b/src/igmpproxy.h
100 index 4df8a79..36a4f04 100644
101 --- a/src/igmpproxy.h
102 +++ b/src/igmpproxy.h
109 #include <sys/socket.h>
111 -#include <sys/time.h>
112 #include <sys/ioctl.h>
113 #include <sys/param.h>
114 +#include <sys/select.h>
117 #include <netinet/in.h>