mirror of
https://github.com/fumiama/simple-http-server.git
synced 2026-06-10 13:00:28 +08:00
改用splice
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -53,3 +53,4 @@ dkms.conf
|
|||||||
|
|
||||||
build
|
build
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.vscode
|
||||||
|
|||||||
14
server.c
14
server.c
@@ -6,6 +6,8 @@
|
|||||||
*
|
*
|
||||||
* Modified June 2021 by Fumiama(源文雨)
|
* Modified June 2021 by Fumiama(源文雨)
|
||||||
*/
|
*/
|
||||||
|
/* See feature_test_macros(7) */
|
||||||
|
#define _GNU_SOURCE 1
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -20,6 +22,7 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#if !__APPLE__
|
#if !__APPLE__
|
||||||
@@ -267,13 +270,10 @@ static void execute_cgi(int client, const char *path, const char *method, const
|
|||||||
if(read(cgi_output[0], (char*)&cnt, sizeof(uint32_t)) > 0) {
|
if(read(cgi_output[0], (char*)&cnt, sizeof(uint32_t)) > 0) {
|
||||||
printf("cgi msg cnt: %u bytes.\n", cnt);
|
printf("cgi msg cnt: %u bytes.\n", cnt);
|
||||||
if(cnt > 0) {
|
if(cnt > 0) {
|
||||||
int len = 0;
|
loff_t len = 0;
|
||||||
#if __APPLE__
|
loff_t offin = 0;
|
||||||
sendfile(cgi_output[0], client, 0, &len, &hdtr, 0);
|
splice(cgi_output[0], &offin, client, &len, cnt, SPLICE_F_GIFT);
|
||||||
#else
|
printf("cgi send %ld bytes\n", len);
|
||||||
sendfile(client, cgi_output[0], &len, cnt);
|
|
||||||
#endif
|
|
||||||
printf("cgi send %d bytes\n", len);
|
|
||||||
}
|
}
|
||||||
} else cannot_execute(client);
|
} else cannot_execute(client);
|
||||||
close(cgi_output[0]);
|
close(cgi_output[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user