From 21399ac8c74cc5dfcef971c804cbc01b3b0d8e21 Mon Sep 17 00:00:00 2001 From: lxsang Date: Thu, 11 Apr 2019 11:00:52 +0200 Subject: [PATCH] add debug code to invertigates looping buh --- http_server.c | 14 ++++++++++++++ http_server.h | 11 +++++++++++ httpd.c | 25 +++++++++++++++++++++++++ libs/scheduler.c | 3 ++- libs/scheduler.h | 10 +++++++++- 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/http_server.c b/http_server.c index 4617d7e..ab6d9b1 100644 --- a/http_server.c +++ b/http_server.c @@ -190,6 +190,7 @@ void *accept_request(void *data) return task; } task->handle = accept_request; + task->status = TASK_ACCEPT; return task; } // perform the ssl handshake if enabled @@ -207,6 +208,7 @@ void *accept_request(void *data) case SSL_ERROR_WANT_WRITE: case SSL_ERROR_NONE: //LOG("RETRY SSL %d\n", client->sock); + task->status = TASK_ACCEPT; task->handle = accept_request; //task->priority = HIGH_PRIORITY; //task->type = LIGHT; @@ -223,6 +225,7 @@ void *accept_request(void *data) // reset the waiting client->last_wait = 0; task->handle = accept_request; + task->status = TASK_ACCEPT; LOG("Handshake finish for %d\n", client->sock); return task; } @@ -239,6 +242,7 @@ void *accept_request(void *data) return task; } task->handle = accept_request; + task->status = TASK_ACCEPT; return task; } } @@ -279,6 +283,7 @@ void *accept_request(void *data) // decode request // now return the task task->handle = decode_request_header; + task->status = TASK_DECODE_HEADER; return task; } @@ -378,6 +383,7 @@ void *resolve_request(void *data) { task->type = HEAVY; task->handle = serve_file; + task->status = TASK_SERVE_FILE; } return task; } @@ -610,6 +616,8 @@ void *decode_request_header(void *data) free(host); // header ok, now checkmethod antd_task_t *task = antd_create_task(decode_request, (void *)rq, NULL); + task->status = TASK_DECODE_RQ; + task->priority++; return task; } @@ -643,11 +651,13 @@ void *decode_request(void *data) } // resolve task task->handle = resolve_request; + task->status = TASK_RESOLVE_RQ; return task; } else if (strcmp(method, "POST") == 0) { task->handle = resolve_request; + task->status = TASK_RESOLVE_RQ; //task->type = HEAVY; return task; } @@ -791,6 +801,7 @@ void *decode_multi_part_request(void *data, const char *ctype) antd_request_t *rq = (antd_request_t *)data; antd_task_t *task = antd_create_task(NULL, (void *)rq, NULL); task->priority++; + task->status = TASK_DECODE_MP_DATA; //dictionary dic = NULL; boundary = strsep(&str_copy, "="); //discard first part boundary = str_copy; @@ -968,6 +979,7 @@ void *decode_multi_part_request_data(void *data) // continue upload task->type = HEAVY; task->handle = decode_multi_part_request_data; + task->status = TASK_DECODE_MP_DATA; } free(line); free(boundend); @@ -1095,12 +1107,14 @@ void *execute_plugin(void *data, const char *pname) { task->handle = fn; task->type = HEAVY; + task->status = TASK_EXEC_PLUGIN_RAW; } else { free(task); task = antd_create_task(decode_post_request, (void *)rq, fn); task->priority++; + task->status = TASK_EXEC_PLUGIN_COOK; } return task; } diff --git a/http_server.h b/http_server.h index da8a30f..b2ca701 100644 --- a/http_server.h +++ b/http_server.h @@ -17,6 +17,17 @@ #define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0 #define CONFIG "config.ini" +// define all task status here +// for debug purpose +#define TASK_ACCEPT 0x01 +#define TASK_DECODE_HEADER 0x02; +#define TASK_DECODE_RQ 0x03; +#define TASK_RESOLVE_RQ 0x04; +#define TASK_EXEC_PLUGIN_RAW 0x05; // with raw data +#define TASK_EXEC_PLUGIN_COOK 0x06; // with decoded post request data +#define TASK_SERVE_FILE 0x07; +#define TASK_DECODE_MP_DATA 0x08; + config_t* config(); void destroy_config(); void load_config(const char* file); diff --git a/httpd.c b/httpd.c index 3412453..1fe5436 100644 --- a/httpd.c +++ b/httpd.c @@ -99,6 +99,25 @@ void stop_serve(int dummy) { close(server_sock); sigprocmask(SIG_UNBLOCK, &mask, NULL); } +void antd_scheduler_dump(antd_scheduler_t* scheduler) +{ + antd_task_queue_t queue = NULL; + antd_task_item_t it = NULL; + LOG("[[[[SCHEDULER]]]] : dumping all value:\n"); + pthread_mutex_lock(&scheduler->scheduler_lock); + for(int i = 0; i < N_PRIORITY; i++) + { + queue = scheduler->task_queue[i]; + for(it = queue; it != NULL && it->next != NULL; it = it->next) + { + antd_request_t* request = it->task->data; + LOG("From: %s [%d]\n", request->client->ip, request->client->sock); + LOG("\tStamp: %ul\n", it->task->stamp); + LOG("\tstatus: %x\n", it->task->status); + } + } + pthread_mutex_unlock(&scheduler->scheduler_lock); +} int main(int argc, char* argv[]) { // load the config first @@ -156,6 +175,7 @@ int main(int argc, char* argv[]) { continue; } + // just dump the scheduler when we have a connection antd_client_t* client = (antd_client_t*)malloc(sizeof(antd_client_t)); antd_request_t* request = (antd_request_t*)malloc(sizeof(*request)); request->client = client; @@ -169,6 +189,10 @@ int main(int argc, char* argv[]) client_ip = inet_ntoa(client_name.sin_addr); client->ip = strdup(client_ip); LOG("Client IP: %s\n", client_ip); + if(strcmp(client->ip, "193.48.235.2") == 0) + { + antd_scheduler_dump(&scheduler); + } //LOG("socket: %d\n", client_sock); } @@ -205,6 +229,7 @@ int main(int argc, char* argv[]) #endif // create callback for the server task = antd_create_task(accept_request,(void*)request, finish_request ); + task->status = TASK_ACCEPT; //task->type = LIGHT; antd_add_task(&scheduler, task); } diff --git a/libs/scheduler.c b/libs/scheduler.c index 84f3fe9..c3dc833 100644 --- a/libs/scheduler.c +++ b/libs/scheduler.c @@ -225,6 +225,7 @@ antd_task_t* antd_create_task(void* (*handle)(void*), void *data, void* (*callba task->callback = callback_of(callback); task->priority = NORMAL_PRIORITY; task->type = LIGHT; + task->status = NOSTATUS; return task; } @@ -347,4 +348,4 @@ void antd_wait(antd_scheduler_t* scheduler) sem_wait(scheduler->scheduler_sem); } } -} \ No newline at end of file +} diff --git a/libs/scheduler.h b/libs/scheduler.h index 9d9bf4c..4627276 100644 --- a/libs/scheduler.h +++ b/libs/scheduler.h @@ -9,7 +9,7 @@ #define NORMAL_PRIORITY ((int)((N_PRIORITY - 1) / 2)) #define LOW_PRIORITY (N_PRIORITY - 1) #define HIGH_PRIORITY 0 - +#define NOSTATUS 0x00 typedef enum { LIGHT, HEAVY } antd_task_type_t; // callback definition typedef struct __callback_t{ @@ -27,6 +27,13 @@ typedef struct { higher value is lower priority */ uint8_t priority; + /* + The status of a task + should be set by the application + default value 0x00 means that + there is no status set + */ + uint8_t status; /* the callback */ @@ -109,4 +116,5 @@ int antd_task_schedule(antd_scheduler_t*); wait for event */ void antd_wait(antd_scheduler_t*); + #endif \ No newline at end of file