[Aggregator] More monitor_requests() refactoring
Create scan_request_list() out of monitor_requests().
This commit is contained in:
parent
5b6f40f59d
commit
0e913a2938
4
TODO.t2t
4
TODO.t2t
|
@ -96,9 +96,7 @@ Work to do in OwlPS
|
||||||
|
|
||||||
- Allow a different aggregation timeout for each request type.
|
- Allow a different aggregation timeout for each request type.
|
||||||
|
|
||||||
- Refactoring:
|
- Refactor got_request().
|
||||||
- monitor_requests()
|
|
||||||
- got_request()
|
|
||||||
|
|
||||||
- got_request(): option for the maximal difference time
|
- got_request(): option for the maximal difference time
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,9 @@ int read_loop(int sockfd) ;
|
||||||
void got_request(owl_captured_request request) ;
|
void got_request(owl_captured_request request) ;
|
||||||
|
|
||||||
void* monitor_requests(void *NULL_value) ;
|
void* monitor_requests(void *NULL_value) ;
|
||||||
|
void scan_request_list(FILE *const stream,
|
||||||
|
const int sockfd,
|
||||||
|
const struct sockaddr_in *const serv) ;
|
||||||
void flush_request_list(FILE *const stream,
|
void flush_request_list(FILE *const stream,
|
||||||
const int sockfd,
|
const int sockfd,
|
||||||
const struct sockaddr_in *const serv) ;
|
const struct sockaddr_in *const serv) ;
|
||||||
|
|
|
@ -788,20 +788,12 @@ void got_request(owl_captured_request request)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Thread function. Monitors the list and sends information to the
|
* Thread function. Monitors the list and prints/sends information to the
|
||||||
* localisation server when the timeout is reached.
|
* localisation server when the timeout is reached.
|
||||||
*/
|
*/
|
||||||
void* monitor_requests(void *NULL_value)
|
void* monitor_requests(void *NULL_value)
|
||||||
{
|
{
|
||||||
request_list *request_ptr, *request_prev ;
|
|
||||||
owl_timestamp current_time ;
|
|
||||||
FILE *stream = NULL ;
|
FILE *stream = NULL ;
|
||||||
uint_fast32_t sub ; // owl_time_elapsed_ms() result
|
|
||||||
|
|
||||||
uint_fast32_t aggregate_timeout =
|
|
||||||
cfg_getint(cfg, "aggregate_timeout") ;
|
|
||||||
uint_fast32_t keep_timeout = cfg_getint(cfg, "keep_timeout") ;
|
|
||||||
|
|
||||||
struct sockaddr_in serv;
|
struct sockaddr_in serv;
|
||||||
struct sockaddr_in client ;
|
struct sockaddr_in client ;
|
||||||
int sockfd;
|
int sockfd;
|
||||||
|
@ -832,15 +824,44 @@ void* monitor_requests(void *NULL_value)
|
||||||
|
|
||||||
/* Main loop */
|
/* Main loop */
|
||||||
while (owl_run)
|
while (owl_run)
|
||||||
|
scan_request_list(stream, sockfd, &serv) ;
|
||||||
|
|
||||||
|
/* Flush the requests' list prior to return */
|
||||||
|
flush_request_list(stream, sockfd, &serv) ;
|
||||||
|
|
||||||
|
/* Close output file & socket */
|
||||||
|
pthread_cleanup_pop(1) ;
|
||||||
|
pthread_cleanup_pop(1) ;
|
||||||
|
|
||||||
|
pthread_exit(NULL_value) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Goes through the requests' list, output the requests that are older
|
||||||
|
* than the aggregation timeout, deletes the requests that are older
|
||||||
|
* than the keep timeout.
|
||||||
|
*/
|
||||||
|
void scan_request_list(FILE *const stream,
|
||||||
|
const int sockfd,
|
||||||
|
const struct sockaddr_in *const serv)
|
||||||
{
|
{
|
||||||
request_prev = NULL ;
|
request_list *request_ptr ;
|
||||||
|
request_list *request_prev = NULL ;
|
||||||
|
|
||||||
|
owl_timestamp current_time ;
|
||||||
|
uint_fast32_t sub ; // owl_time_elapsed_ms() result
|
||||||
|
|
||||||
|
uint_fast32_t aggregate_timeout =
|
||||||
|
cfg_getint(cfg, "aggregate_timeout") ;
|
||||||
|
uint_fast32_t keep_timeout = cfg_getint(cfg, "keep_timeout") ;
|
||||||
|
|
||||||
sem_wait(&lock_requests) ;
|
sem_wait(&lock_requests) ;
|
||||||
|
|
||||||
owl_timestamp_now(¤t_time) ;
|
owl_timestamp_now(¤t_time) ;
|
||||||
request_ptr = requests ;
|
request_ptr = requests ;
|
||||||
|
|
||||||
while (request_ptr != NULL) // Parsing list
|
while (request_ptr != NULL) // Go through the list
|
||||||
{
|
{
|
||||||
sub = owl_time_elapsed_ms(&request_ptr->start_time,
|
sub = owl_time_elapsed_ms(&request_ptr->start_time,
|
||||||
¤t_time) ;
|
¤t_time) ;
|
||||||
|
@ -856,7 +877,7 @@ void* monitor_requests(void *NULL_value)
|
||||||
" %"PRIuFAST32" > %"PRIuFAST32"\n",
|
" %"PRIuFAST32" > %"PRIuFAST32"\n",
|
||||||
sub, aggregate_timeout) ;
|
sub, aggregate_timeout) ;
|
||||||
|
|
||||||
output_request(request_ptr, stream, sockfd, &serv) ;
|
output_request(request_ptr, stream, sockfd, serv) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -898,16 +919,6 @@ void* monitor_requests(void *NULL_value)
|
||||||
owl_msleep(cfg_getint(cfg, "check_interval")) ;
|
owl_msleep(cfg_getint(cfg, "check_interval")) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flush the requests' list prior to return */
|
|
||||||
flush_request_list(stream, sockfd, &serv) ;
|
|
||||||
|
|
||||||
/* Close output file & socket */
|
|
||||||
pthread_cleanup_pop(1) ;
|
|
||||||
pthread_cleanup_pop(1) ;
|
|
||||||
|
|
||||||
pthread_exit(NULL_value) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prints and sends all the requests in the requests' list and frees
|
* Prints and sends all the requests in the requests' list and frees
|
||||||
|
|
Loading…
Reference in New Issue