[lib] Refactor time_elapsed()
owl_time_elapsed() now returns a TIMESTAMP. The new function owl_time_elapsed_ms() returns a value in milliseconds (old behaviour).
This commit is contained in:
parent
788a61a712
commit
33f863e2e1
|
@ -413,7 +413,7 @@ void* monitor_couples()
|
|||
TIMESTAMP current_time ;
|
||||
FILE *fd = NULL ;
|
||||
char *mac_string ;
|
||||
uint_fast32_t sub ; // time_elapsed() result
|
||||
uint_fast32_t sub ; // owl_time_elapsed_ms() result
|
||||
|
||||
uint_fast32_t aggregate_timeout =
|
||||
cfg_getint(cfg, "aggregate_timeout") ;
|
||||
|
@ -453,7 +453,8 @@ void* monitor_couples()
|
|||
|
||||
while (couple_ptr != NULL) // Parsing list
|
||||
{
|
||||
sub = owl_time_elapsed(couple_ptr->start_time, current_time) ;
|
||||
sub = owl_time_elapsed_ms(couple_ptr->start_time,
|
||||
current_time) ;
|
||||
|
||||
// If the couple was not treated already
|
||||
if (couple_ptr->info != NULL)
|
||||
|
@ -632,8 +633,8 @@ void got_couple_info(couple_message message)
|
|||
{ // Research criterion: MAC and transmission time
|
||||
if (owl_mac_equals(message.mobile_mac_addr_bytes,
|
||||
tmp_couple->mobile_mac_addr_bytes) == 1
|
||||
&& owl_time_elapsed(message.request_time,
|
||||
tmp_couple->request_time) == 0)
|
||||
&& owl_time_elapsed_ms(message.request_time,
|
||||
tmp_couple->request_time) == 0)
|
||||
break ; // If the couple exists, we stop on it
|
||||
tmp_couple = tmp_couple->next ;
|
||||
}
|
||||
|
@ -647,8 +648,8 @@ void got_couple_info(couple_message message)
|
|||
// TODO : define an option for the maximal difference time.
|
||||
if (owl_mac_equals(message.mobile_mac_addr_bytes,
|
||||
tmp_couple->mobile_mac_addr_bytes) == 1
|
||||
&& owl_time_elapsed(message.start_time,
|
||||
tmp_couple->request_time) <= 10)
|
||||
&& owl_time_elapsed_ms(message.start_time,
|
||||
tmp_couple->request_time) <= 10)
|
||||
break ; // If the couple exists, we stop on it
|
||||
tmp_couple = tmp_couple->next ;
|
||||
}
|
||||
|
@ -919,7 +920,7 @@ void delete_old_aps()
|
|||
owl_timestamp_now(&now) ;
|
||||
|
||||
while (token_aps != NULL)
|
||||
if (owl_time_elapsed(token_aps->last_seen, now) >
|
||||
if (owl_time_elapsed_ms(token_aps->last_seen, now) >
|
||||
(uint_fast32_t) cfg_getint(cfg, "ap_keep_timeout") * 1000)
|
||||
delete_ap(token_aps) ;
|
||||
else
|
||||
|
|
|
@ -163,14 +163,26 @@ void owl_timestamp_to_string(char *dst, TIMESTAMP src)
|
|||
/*
|
||||
* Returns the time (in milliseconds) between two dates.
|
||||
*/
|
||||
uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf)
|
||||
uint_fast32_t owl_time_elapsed_ms(const TIMESTAMP d1, const TIMESTAMP d2)
|
||||
{
|
||||
uint_fast32_t elapsed_ms =
|
||||
abs(owl_timestamp_to_ms(sup) - owl_timestamp_to_ms(inf)) ;
|
||||
return owl_timestamp_to_ms(owl_time_elapsed(d1, d2)) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Returns a TIMESTAMP storing the time between two dates.
|
||||
*/
|
||||
TIMESTAMP owl_time_elapsed(const TIMESTAMP d1, const TIMESTAMP d2)
|
||||
{
|
||||
TIMESTAMP elapsed ;
|
||||
elapsed.tv_sec = abs(d1.tv_sec - d2.tv_sec) ;
|
||||
elapsed.tv_nsec = abs(d1.tv_nsec - d2.tv_nsec) ;
|
||||
#ifdef DEBUG
|
||||
printf("time_elapsed(): %"PRIuFAST32"ms\n", elapsed_ms) ;
|
||||
printf("time_elapsed(): %"PRIu64"ms\n",
|
||||
owl_timestamp_to_ms(elapsed)) ;
|
||||
#endif
|
||||
return elapsed_ms ;
|
||||
return elapsed ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -234,7 +234,8 @@ TIMESTAMP owl_timespec_to_timestamp(const struct timespec d) ;
|
|||
TIMESTAMP owl_timeval_to_timestamp(const struct timeval d) ;
|
||||
void owl_timestamp_to_string(char *dst, TIMESTAMP src) ;
|
||||
uint64_t owl_timestamp_to_ms(TIMESTAMP date) ;
|
||||
uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;
|
||||
uint_fast32_t owl_time_elapsed_ms(const TIMESTAMP d1, const TIMESTAMP d2) ;
|
||||
TIMESTAMP owl_time_elapsed(const TIMESTAMP d1, const TIMESTAMP d2) ;
|
||||
TIMESTAMP owl_hton_timestamp(TIMESTAMP date) ;
|
||||
TIMESTAMP owl_ntoh_timestamp(TIMESTAMP date) ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue