use timeradd/sub/cmp.
Obtained from: KAME
This commit is contained in:
parent
2a9e935823
commit
d05ae8c388
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=124523
@ -79,20 +79,6 @@ char *otherconf_script;
|
||||
*/
|
||||
#define PROBE_INTERVAL 60
|
||||
|
||||
/* utility macros */
|
||||
/* a < b */
|
||||
#define TIMEVAL_LT(a, b) (((a).tv_sec < (b).tv_sec) ||\
|
||||
(((a).tv_sec == (b).tv_sec) && \
|
||||
((a).tv_usec < (b).tv_usec)))
|
||||
|
||||
/* a <= b */
|
||||
#define TIMEVAL_LEQ(a, b) (((a).tv_sec < (b).tv_sec) ||\
|
||||
(((a).tv_sec == (b).tv_sec) &&\
|
||||
((a).tv_usec <= (b).tv_usec)))
|
||||
|
||||
/* a == b */
|
||||
#define TIMEVAL_EQ(a, b) (((a).tv_sec==(b).tv_sec) && ((a).tv_usec==(b).tv_usec))
|
||||
|
||||
int main __P((int, char **));
|
||||
|
||||
/* static variables and functions */
|
||||
@ -106,10 +92,6 @@ static int ifreconfig __P((char *));
|
||||
#endif
|
||||
static int make_packet __P((struct ifinfo *));
|
||||
static struct timeval *rtsol_check_timer __P((void));
|
||||
static void TIMEVAL_ADD __P((struct timeval *, struct timeval *,
|
||||
struct timeval *));
|
||||
static void TIMEVAL_SUB __P((struct timeval *, struct timeval *,
|
||||
struct timeval *));
|
||||
|
||||
static void rtsold_set_dump_file __P((int));
|
||||
static void usage __P((char *));
|
||||
@ -557,7 +539,7 @@ rtsol_check_timer()
|
||||
rtsol_timer = tm_max;
|
||||
|
||||
for (ifinfo = iflist; ifinfo; ifinfo = ifinfo->next) {
|
||||
if (TIMEVAL_LEQ(ifinfo->expire, now)) {
|
||||
if (timercmp(&ifinfo->expire, &now, <=)) {
|
||||
if (dflag > 1)
|
||||
warnmsg(LOG_DEBUG, __func__,
|
||||
"timer expiration on %s, "
|
||||
@ -631,18 +613,18 @@ rtsol_check_timer()
|
||||
rtsol_timer_update(ifinfo);
|
||||
}
|
||||
|
||||
if (TIMEVAL_LT(ifinfo->expire, rtsol_timer))
|
||||
if (timercmp(&ifinfo->expire, &rtsol_timer, <))
|
||||
rtsol_timer = ifinfo->expire;
|
||||
}
|
||||
|
||||
if (TIMEVAL_EQ(rtsol_timer, tm_max)) {
|
||||
if (timercmp(&rtsol_timer, &tm_max, ==)) {
|
||||
warnmsg(LOG_DEBUG, __func__, "there is no timer");
|
||||
return(NULL);
|
||||
} else if (TIMEVAL_LT(rtsol_timer, now))
|
||||
} else if (timercmp(&rtsol_timer, &now, <))
|
||||
/* this may occur when the interval is too small */
|
||||
returnval.tv_sec = returnval.tv_usec = 0;
|
||||
else
|
||||
TIMEVAL_SUB(&rtsol_timer, &now, &returnval);
|
||||
timersub(&rtsol_timer, &now, &returnval);
|
||||
|
||||
if (dflag > 1)
|
||||
warnmsg(LOG_DEBUG, __func__, "New timer is %ld:%08ld",
|
||||
@ -709,13 +691,13 @@ rtsol_timer_update(struct ifinfo *ifinfo)
|
||||
}
|
||||
|
||||
/* reset the timer */
|
||||
if (TIMEVAL_EQ(ifinfo->timer, tm_max)) {
|
||||
if (timercmp(&ifinfo->timer, &tm_max, ==)) {
|
||||
ifinfo->expire = tm_max;
|
||||
warnmsg(LOG_DEBUG, __func__,
|
||||
"stop timer for %s", ifinfo->ifname);
|
||||
} else {
|
||||
gettimeofday(&now, NULL);
|
||||
TIMEVAL_ADD(&now, &ifinfo->timer, &ifinfo->expire);
|
||||
timeradd(&now, &ifinfo->timer, &ifinfo->expire);
|
||||
|
||||
if (dflag > 1)
|
||||
warnmsg(LOG_DEBUG, __func__,
|
||||
@ -730,39 +712,6 @@ rtsol_timer_update(struct ifinfo *ifinfo)
|
||||
/* timer related utility functions */
|
||||
#define MILLION 1000000
|
||||
|
||||
/* result = a + b */
|
||||
static void
|
||||
TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result)
|
||||
{
|
||||
long l;
|
||||
|
||||
if ((l = a->tv_usec + b->tv_usec) < MILLION) {
|
||||
result->tv_usec = l;
|
||||
result->tv_sec = a->tv_sec + b->tv_sec;
|
||||
} else {
|
||||
result->tv_usec = l - MILLION;
|
||||
result->tv_sec = a->tv_sec + b->tv_sec + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* result = a - b
|
||||
* XXX: this function assumes that a >= b.
|
||||
*/
|
||||
void
|
||||
TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result)
|
||||
{
|
||||
long l;
|
||||
|
||||
if ((l = a->tv_usec - b->tv_usec) >= 0) {
|
||||
result->tv_usec = l;
|
||||
result->tv_sec = a->tv_sec - b->tv_sec;
|
||||
} else {
|
||||
result->tv_usec = MILLION + l;
|
||||
result->tv_sec = a->tv_sec - b->tv_sec - 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rtsold_set_dump_file(sig)
|
||||
int sig;
|
||||
|
Loading…
Reference in New Issue
Block a user