From 0daef95c25aa8a9c4122c83d9d9682f70a459717 Mon Sep 17 00:00:00 2001 From: lxsang Date: Fri, 8 Oct 2021 22:47:27 +0200 Subject: [PATCH] scheduler timeout should be configurable --- http_server.c | 5 +++++ httpd.c | 23 +++++++++++++++-------- lib/handle.h | 1 + lib/scheduler.c | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/http_server.c b/http_server.c index f1a560c..1f62997 100644 --- a/http_server.c +++ b/http_server.c @@ -165,6 +165,10 @@ static int config_handler(void *conf, const char *section, const char *name, { pconfig->debug_enable = atoi(value); } + else if (MATCH("SERVER", "scheduler_timeout")) + { + pconfig->scheduler_timeout = atoi(value); + } #ifdef USE_ZLIB else if (MATCH("SERVER", "gzip_enable")) { @@ -274,6 +278,7 @@ void load_config(const char *file) server_config.gzip_enable = 0; server_config.gzip_types = NULL; server_config.debug_enable = 0; + server_config.scheduler_timeout = 30; // 30 s // put it default mimes for (int i = 0; _mimes[i].type != NULL; i++) { diff --git a/httpd.c b/httpd.c index 61e8a1f..1b9691f 100644 --- a/httpd.c +++ b/httpd.c @@ -21,7 +21,7 @@ snprintf(buff, BUFFLEN, ##__VA_ARGS__); \ ret = write(fd, buff, strlen(buff)); -static antd_scheduler_t* scheduler; +static antd_scheduler_t *scheduler; #ifdef USE_OPENSSL @@ -241,7 +241,7 @@ static void antd_monitor(port_config_t *pcnf) antd_scheduler_unlock(scheduler); // create callback for the server task = antd_create_task(accept_request, (void *)request, finish_request, client->last_io); - antd_task_bind_event(task,client->sock,0, TASK_EVT_ON_WRITABLE| TASK_EVT_ON_READABLE); + antd_task_bind_event(task, client->sock, 0, TASK_EVT_ON_WRITABLE | TASK_EVT_ON_READABLE); antd_scheduler_add_task(scheduler, task); } } @@ -299,19 +299,26 @@ void antd_scheduler_destroy_data(void *data) { antd_request_t *rq = (antd_request_t *)data; antd_client_t *proxy = (antd_client_t *)dvalue(rq->request, "PROXY_HANDLE"); - if(proxy) + if (proxy) { close(proxy->sock); } finish_request(data); } +int antd_scheduler_validate_data(antd_task_t *task) +{ + config_t *conf = config(); + LOG("Use server configured scheduler timeout %d", conf->scheduler_timeout); + return !(difftime(time(NULL), task->access_time) > conf->scheduler_timeout); +} + int antd_task_data_id(void *data) { antd_request_t *rq = (antd_request_t *)data; - if(!rq) - return 0; - return antd_scheduler_next_id(scheduler,rq->client->sock); + if (!rq) + return 0; + return antd_scheduler_next_id(scheduler, rq->client->sock); /*UNUSED(data); return antd_scheduler_next_id(scheduler,0);*/ } @@ -339,7 +346,7 @@ int main(int argc, char *argv[]) config_t *conf = config(); // start syslog - if(conf->debug_enable == 1) + if (conf->debug_enable == 1) { setlogmask(LOG_UPTO(LOG_NOTICE)); } @@ -361,7 +368,7 @@ int main(int argc, char *argv[]) #endif // enable scheduler // default to 4 workers - scheduler = antd_scheduler_init( conf->n_workers, conf->stat_fifo_path); + scheduler = antd_scheduler_init(conf->n_workers, conf->stat_fifo_path); if (scheduler == NULL) { ERROR("Unable to initialise scheduler. Exit"); diff --git a/lib/handle.h b/lib/handle.h index d35eeae..789b398 100644 --- a/lib/handle.h +++ b/lib/handle.h @@ -86,6 +86,7 @@ typedef struct int maxcon; int connection; int n_workers; + int scheduler_timeout; int max_upload_size; // ssl int enable_ssl; diff --git a/lib/scheduler.c b/lib/scheduler.c index 076c112..5400b7d 100644 --- a/lib/scheduler.c +++ b/lib/scheduler.c @@ -11,7 +11,7 @@ #include "utils.h" #include "bst.h" -#define MAX_VALIDITY_INTERVAL 30 // s +#define MAX_VALIDITY_INTERVAL 30 #define MAX_FIFO_NAME_SZ 255 // callback definition