1
0
mirror of https://github.com/fumiama/simple-http-server.git synced 2026-06-11 05:20:25 +08:00

完善cgi sendfile

This commit is contained in:
源文雨
2021-06-08 15:14:55 +08:00
parent 64a7fb5eea
commit 6972306aad

View File

@@ -264,17 +264,18 @@ static void execute_cgi(int client, const char *path, const char *method, const
} }
} }
uint32_t cnt = 0; uint32_t cnt = 0;
read(cgi_output[0], (char*)&cnt, sizeof(uint32_t)); if(read(cgi_output[0], (char*)&cnt, sizeof(uint32_t)) > 0) {
if(cnt > 0) { printf("cgi msg cnt: %u bytes.\n", cnt);
int len = 0; if(cnt > 0) {
#if __APPLE__ int len = 0;
sendfile(cgi_output[0], client, 0, &len, &hdtr, 0); #if __APPLE__
#else sendfile(cgi_output[0], client, 0, &len, &hdtr, 0);
sendfile(client, cgi_output[0], &len, cnt); #else
#endif sendfile(client, cgi_output[0], &len, cnt);
printf("cgi send %d bytes\n", len); #endif
} printf("cgi send %d bytes\n", len);
}
} else cannot_execute(client);
close(cgi_output[0]); close(cgi_output[0]);
close(cgi_input[1]); close(cgi_input[1]);
waitpid(pid, &status, 0); waitpid(pid, &status, 0);