-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathzhou.c
More file actions
35 lines (30 loc) · 762 Bytes
/
zhou.c
File metadata and controls
35 lines (30 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* zhou.c 一个简单的web服务器
* email: yiqianniyiye@126.com
*/
#include "server.h"
int main(int argc, char *argv[])
{
int listenfd, connfd, port, clientlen;
struct sockaddr_in clientaddr;
// 检查是否指定了监听端口
if (argc != 2) {
port = PORT; // 使用默认端口
} else {
port = atoi(argv[1]);
}
listenfd = open_listenfd(port);
if (listenfd < 0) {
error_log("open_listenfd error", DEBUGARGS);
}
while (1) {
clientlen = sizeof(clientaddr);
connfd = accept(listenfd, (SA *)&clientaddr, &clientlen);
if (connfd < 0) {
error_log("accept error", DEBUGARGS);
}
doit(connfd);
close(connfd);
}
return 0;
}