mirror of
https://github.com/fumiama/simple-http-server.git
synced 2026-06-09 20:40:41 +08:00
避免broken pipe
This commit is contained in:
11
server.c
11
server.c
@@ -32,6 +32,7 @@ void error_die(const char *);
|
|||||||
void execute_cgi(int, const char *, const char *, const char *);
|
void execute_cgi(int, const char *, const char *, const char *);
|
||||||
off_t get_file_size(const char *);
|
off_t get_file_size(const char *);
|
||||||
int get_line(int, char *, int);
|
int get_line(int, char *, int);
|
||||||
|
void handle_quit(int);
|
||||||
void headers(int, const char *);
|
void headers(int, const char *);
|
||||||
void not_found(int);
|
void not_found(int);
|
||||||
void serve_file(int, const char *);
|
void serve_file(int, const char *);
|
||||||
@@ -333,6 +334,14 @@ int get_line(int sock, char *buf, int size) {
|
|||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/* Handle thread quit signal
|
||||||
|
/**********************************************************************/
|
||||||
|
void handle_quit(int signo) {
|
||||||
|
perror("handle");
|
||||||
|
pthread_exit(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Return the informational HTTP headers about a file. */
|
/* Return the informational HTTP headers about a file. */
|
||||||
/* Parameters: the socket to print the headers on
|
/* Parameters: the socket to print the headers on
|
||||||
@@ -504,6 +513,8 @@ void unimplemented(int client) {
|
|||||||
while (1) {\
|
while (1) {\
|
||||||
client_sock = accept(server_sock, (struct sockaddr *)&client_name, &client_name_len);\
|
client_sock = accept(server_sock, (struct sockaddr *)&client_name, &client_name_len);\
|
||||||
if (client_sock == -1) break;\
|
if (client_sock == -1) break;\
|
||||||
|
signal(SIGQUIT, handle_quit);\
|
||||||
|
signal(SIGPIPE, handle_quit);\
|
||||||
if (pthread_create(&newthread, NULL, accept_request, client_sock) != 0) perror("pthread_create");\
|
if (pthread_create(&newthread, NULL, accept_request, client_sock) != 0) perror("pthread_create");\
|
||||||
}\
|
}\
|
||||||
close(client_sock);\
|
close(client_sock);\
|
||||||
|
|||||||
Reference in New Issue
Block a user