From 6b49b0ca04c9d663fd6356a8154c1329064198d3 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 16:48:14 +0800 Subject: [PATCH] =?UTF-8?q?linux=E4=B8=8B=E9=87=87=E7=94=A8splice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/server.c b/server.c index 026c30d..cc58a1c 100644 --- a/server.c +++ b/server.c @@ -6,6 +6,8 @@ * * Modified June 2021 by Fumiama(源文雨) */ +/* See feature_test_macros(7) */ +#define _GNU_SOURCE 1 #include #include #include @@ -21,6 +23,7 @@ #include #include #include +#include #if !__APPLE__ #include @@ -273,12 +276,16 @@ static void execute_cgi(int client, const char *path, const char *method, const printf("cgi msg cnt: %u bytes.\n", cnt); if(cnt > 0) { int len = 0; - char* data = malloc(cnt); - while(len < cnt) { - len += read(cgi_output[0], data, cnt); - send(client, data, len, 0); - } - if(data) free(data); + #if __APPLE__ + char* data = malloc(cnt); + while(len < cnt) { + len += read(cgi_output[0], data, cnt); + send(client, data, len, 0); + } + if(data) free(data); + #else + len = splice(cgi_output[0], NULL, client, NULL, cnt, SPLICE_F_GIFT); + #endif printf("cgi send %d bytes\n", len); } close(cgi_output[0]);