changed timer_expired function call
This commit is contained in:
parent
e1634906f1
commit
81a2df59df
@ -1163,6 +1163,11 @@ void iperf_run_client(struct iperf_test *test)
|
||||
|
||||
}// while outer timer
|
||||
|
||||
// for last interval
|
||||
test->stats_callback(test);
|
||||
read = test->reporter_callback(test);
|
||||
puts(read);
|
||||
|
||||
// sending STREAM_END packets
|
||||
sp = test->streams;
|
||||
np = sp;
|
||||
|
57
src/timer.c
57
src/timer.c
@ -9,43 +9,64 @@
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
|
||||
|
||||
double timeval_to_double(struct timeval *tv)
|
||||
{
|
||||
double d;
|
||||
|
||||
d = tv->tv_sec + tv->tv_usec /1000000;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
double timeval_diff(struct timeval *tv0, struct timeval *tv1)
|
||||
{
|
||||
return timeval_to_double(tv1) - timeval_to_double(tv0);
|
||||
}
|
||||
|
||||
/*
|
||||
int
|
||||
timer_expired(struct timer *tp)
|
||||
{
|
||||
struct timeval now;
|
||||
double d= 0;
|
||||
if(gettimeofday(&now, NULL) < 0) {
|
||||
perror("gettimeofday");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return tp->end.tv_sec <= now.tv_sec;
|
||||
d = timeval_to_double(&tp->end) - timeval_to_double(&now);
|
||||
|
||||
return d <= 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int
|
||||
timer_expired_micro(struct timer *tp)
|
||||
timer_expired(struct timer *tp)
|
||||
{
|
||||
|
||||
struct timeval now;
|
||||
int64_t diff= 0, current= 0;
|
||||
int64_t end = 0, current= 0, diff= 0;
|
||||
if(gettimeofday(&now, NULL) < 0) {
|
||||
perror("gettimeofday");
|
||||
return -1;
|
||||
}
|
||||
|
||||
diff+= tp->end.tv_sec * 1000000 ;
|
||||
diff+= tp->end.tv_usec;
|
||||
end+= tp->end.tv_sec * 1000000 ;
|
||||
end+= tp->end.tv_usec;
|
||||
|
||||
current+= now.tv_sec * 1000000 ;
|
||||
current+= now.tv_usec;
|
||||
|
||||
return diff <= current;
|
||||
diff = end - current;
|
||||
|
||||
return diff <= 0;
|
||||
|
||||
// currently using microsecond limit. Else we need to introduce timespec instread of timeval
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct timer *
|
||||
new_timer(time_t sec, suseconds_t usec)
|
||||
{
|
||||
@ -61,10 +82,7 @@ new_timer(time_t sec, suseconds_t usec)
|
||||
tp->end.tv_sec = tp->begin.tv_sec + (time_t) sec;
|
||||
tp->end.tv_usec = tp->begin.tv_usec + (time_t) usec;
|
||||
|
||||
if( sec != 0)
|
||||
tp->expired = timer_expired;
|
||||
else
|
||||
tp->expired = timer_expired_micro;
|
||||
|
||||
return tp;
|
||||
}
|
||||
@ -100,20 +118,3 @@ delay(int64_t ns)
|
||||
}
|
||||
|
||||
|
||||
double timeval_to_double(struct timeval *tv)
|
||||
{
|
||||
double d;
|
||||
|
||||
d = tv->tv_sec + tv->tv_usec /1000000;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
double timeval_diff(struct timeval *tv0, struct timeval *tv1)
|
||||
{
|
||||
return timeval_to_double(tv1) - timeval_to_double(tv0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user