From b660869a179936abf7143af86cab93d05f6d6e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 8 Jun 2021 14:32:28 +0800 Subject: [PATCH] =?UTF-8?q?readline=E6=94=B9=E7=94=A8sendfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server.c b/server.c index 3876cd9..b30f2f1 100644 --- a/server.c +++ b/server.c @@ -263,8 +263,16 @@ static void execute_cgi(int client, const char *path, const char *method, const i += cnt; } } - int cnt = 0; - while ((cnt = read(cgi_output[0], buf, 1024)) > 0) send(client, buf, cnt, 0); + uint32_t cnt = 0; + read(cgi_output[0], (char*)&cnt, sizeof(uint32_t)); + if(cnt > 0) { + int len = 0; + #if __APPLE__ + sendfile(cgi_output[0], client, 0, &len, &hdtr, 0); + #else + sendfile(client, cgi_output[0], &len, cnt); + #endif + } close(cgi_output[0]); close(cgi_input[1]);