3
3
#define IPPROTO_TCP 6
4
4
#define SO_REUSEADDR 2
5
5
#define SOL_SOCKET 1
6
- #define SHUT_RDWR 2
7
6
#define O_RDONLY 0
8
7
9
8
typedef unsigned short uint16_t ;
@@ -27,7 +26,6 @@ int close(int fd);
27
26
int socket (int domain , int type , int protocol );
28
27
int accept (int socket , sockaddr_in_t * restrict address ,
29
28
socklen_t * restrict address_len );
30
- int shutdown (int socket , int how );
31
29
int bind (int socket , const sockaddr_in_t * address , socklen_t address_len );
32
30
int listen (int socket , int backlog );
33
31
int setsockopt (int socket , int level , int option_name , const void * option_value ,
@@ -99,11 +97,6 @@ static void http_consume(int clientfd, char *http_buf, size_t buf_len) {
99
97
}
100
98
}
101
99
102
- static void http_drop (int clientfd ) {
103
- shutdown (clientfd , SHUT_RDWR );
104
- close (clientfd );
105
- }
106
-
107
100
/*
108
101
* we're supposed to send content-length but shutting down the
109
102
* socket seems to be enough, saves some code
@@ -138,7 +131,6 @@ static int http_serve(int clientfd, const char *file_path, char *http_buf,
138
131
if (n < 0 ) {
139
132
perror ("read" );
140
133
}
141
- http_drop (clientfd );
142
134
return 0 ;
143
135
}
144
136
@@ -179,6 +171,7 @@ int main(int argc, char *argv[]) {
179
171
} else if (pid == 0 ) {
180
172
return http_serve (clientfd , argv [2 ], http_buf , sizeof (http_buf ));
181
173
}
174
+ close (clientfd );
182
175
}
183
176
return 0 ;
184
177
}
0 commit comments