mirror of
https://github.com/fumiama/simple-http-server.git
synced 2026-06-05 08:40:24 +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 *);
|
||||
off_t get_file_size(const char *);
|
||||
int get_line(int, char *, int);
|
||||
void handle_quit(int);
|
||||
void headers(int, const char *);
|
||||
void not_found(int);
|
||||
void serve_file(int, const char *);
|
||||
@@ -333,6 +334,14 @@ int get_line(int sock, char *buf, int size) {
|
||||
return (i);
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
/* Handle thread quit signal
|
||||
/**********************************************************************/
|
||||
void handle_quit(int signo) {
|
||||
perror("handle");
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
/* Return the informational HTTP headers about a file. */
|
||||
/* Parameters: the socket to print the headers on
|
||||
@@ -504,6 +513,8 @@ void unimplemented(int client) {
|
||||
while (1) {\
|
||||
client_sock = accept(server_sock, (struct sockaddr *)&client_name, &client_name_len);\
|
||||
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");\
|
||||
}\
|
||||
close(client_sock);\
|
||||
|
||||
Reference in New Issue
Block a user