From a1f23695ac0d0f012542649c5a765d3c403d21b2 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 00:38:20 +0800 Subject: [PATCH] =?UTF-8?q?cgi=E4=B8=80=E6=AC=A1=E5=8F=91=E9=80=81?= =?UTF-8?q?=E4=B8=80=E6=89=B9=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server.c b/server.c index 7624c71..24c825b 100644 --- a/server.c +++ b/server.c @@ -206,7 +206,6 @@ void execute_cgi(int client, const char *path, const char *method, const char *q pid_t pid; int status; int i; - char c; int numchars = 1; int content_length = -1; @@ -273,11 +272,15 @@ void execute_cgi(int client, const char *path, const char *method, const char *q close(cgi_output[1]); close(cgi_input[0]); if (strcasecmp(method, "POST") == 0) - for (i = 0; i < content_length; i++) { - recv(client, &c, 1, 0); - write(cgi_input[1], &c, 1); + for (i = 0; i < content_length;) { + int cnt = recv(client, buf, 1024, 0); + if(cnt > 0) { + write(cgi_input[1], buf, cnt); + i += cnt; + } } - while (read(cgi_output[0], &c, 1) > 0) send(client, &c, 1, 0); + int cnt = 0; + while ((cnt = read(cgi_output[0], buf, 1024)) > 0) send(client, buf, cnt, 0); close(cgi_output[0]); close(cgi_input[1]);