From 899687d25582bdfeb0fc85a60b0d0fa39993c559 Mon Sep 17 00:00:00 2001 From: lxsang Date: Sat, 30 Jan 2021 22:38:43 +0100 Subject: [PATCH] use both readable event and timeout event --- http_server.c | 12 ++++++++++-- httpd.c | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/http_server.c b/http_server.c index 07db283..e93681c 100644 --- a/http_server.c +++ b/http_server.c @@ -785,7 +785,7 @@ static void *proxy_monitor(void *data) ret = 0; break; } - sz2 = read_buf(proxy, buf, BUFFLEN); + sz2 = antd_recv_upto(proxy, buf, BUFFLEN); if (sz2 < 0 || (sz2 > 0 && antd_send(rq->client, buf, sz2) != sz2)) { ret = 0; @@ -812,9 +812,17 @@ static void *proxy_monitor(void *data) return task; } } + if(pfd[0].revents & POLLIN) + { + antd_task_bind_event(task, proxy->sock, 0, TASK_EVT_ON_READABLE); + } + else + { + antd_task_bind_event(task, proxy->sock, 100u, TASK_EVT_ON_TIMEOUT); + } task->handle = proxy_monitor; task->access_time = rq->client->last_io; - antd_task_bind_event(task, proxy->sock, 0, TASK_EVT_ON_READABLE); + antd_task_bind_event(task, rq->client->sock, 0, TASK_EVT_ON_READABLE); return task; } diff --git a/httpd.c b/httpd.c index 0e36283..e14930e 100644 --- a/httpd.c +++ b/httpd.c @@ -308,12 +308,12 @@ void antd_scheduler_destroy_data(void *data) int antd_task_data_id(void *data) { - /*antd_request_t *rq = (antd_request_t *)data; + antd_request_t *rq = (antd_request_t *)data; if(!rq) return 0; - return antd_scheduler_next_id(scheduler,rq->client->sock);*/ - UNUSED(data); - return antd_scheduler_next_id(scheduler,0); + return antd_scheduler_next_id(scheduler,rq->client->sock); + /*UNUSED(data); + return antd_scheduler_next_id(scheduler,0);*/ } int main(int argc, char *argv[])