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
|
}// while outer timer
|
||||||
|
|
||||||
|
// for last interval
|
||||||
|
test->stats_callback(test);
|
||||||
|
read = test->reporter_callback(test);
|
||||||
|
puts(read);
|
||||||
|
|
||||||
// sending STREAM_END packets
|
// sending STREAM_END packets
|
||||||
sp = test->streams;
|
sp = test->streams;
|
||||||
np = sp;
|
np = sp;
|
||||||
|
65
src/timer.c
65
src/timer.c
@ -9,41 +9,62 @@
|
|||||||
|
|
||||||
#include "timer.h"
|
#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
|
int
|
||||||
timer_expired(struct timer *tp)
|
timer_expired(struct timer *tp)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
double d= 0;
|
||||||
if(gettimeofday(&now, NULL) < 0) {
|
if(gettimeofday(&now, NULL) < 0) {
|
||||||
perror("gettimeofday");
|
perror("gettimeofday");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tp->end.tv_sec <= now.tv_sec;
|
d = timeval_to_double(&tp->end) - timeval_to_double(&now);
|
||||||
|
|
||||||
|
return d <= 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
timer_expired_micro(struct timer *tp)
|
timer_expired(struct timer *tp)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
int64_t diff= 0, current= 0;
|
int64_t end = 0, current= 0, diff= 0;
|
||||||
if(gettimeofday(&now, NULL) < 0) {
|
if(gettimeofday(&now, NULL) < 0) {
|
||||||
perror("gettimeofday");
|
perror("gettimeofday");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
diff+= tp->end.tv_sec * 1000000 ;
|
end+= tp->end.tv_sec * 1000000 ;
|
||||||
diff+= tp->end.tv_usec;
|
end+= tp->end.tv_usec;
|
||||||
|
|
||||||
current+= now.tv_sec * 1000000 ;
|
current+= now.tv_sec * 1000000 ;
|
||||||
current+= now.tv_usec;
|
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 *
|
struct timer *
|
||||||
@ -60,12 +81,9 @@ new_timer(time_t sec, suseconds_t usec)
|
|||||||
memcpy(&tp->end, &tp->begin, sizeof(struct timer));
|
memcpy(&tp->end, &tp->begin, sizeof(struct timer));
|
||||||
tp->end.tv_sec = tp->begin.tv_sec + (time_t) sec;
|
tp->end.tv_sec = tp->begin.tv_sec + (time_t) sec;
|
||||||
tp->end.tv_usec = tp->begin.tv_usec + (time_t) usec;
|
tp->end.tv_usec = tp->begin.tv_usec + (time_t) usec;
|
||||||
|
|
||||||
|
tp->expired = timer_expired;
|
||||||
|
|
||||||
if( sec != 0)
|
|
||||||
tp->expired = timer_expired;
|
|
||||||
else
|
|
||||||
tp->expired = timer_expired_micro;
|
|
||||||
|
|
||||||
return tp;
|
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