-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
45 lines (37 loc) · 1.09 KB
/
main.c
File metadata and controls
45 lines (37 loc) · 1.09 KB
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
36
37
38
39
40
41
42
43
44
/* $begin tinymain */
/*
* tiny.c - A simple, iterative HTTP/1.0 Web server that uses the
* GET method to serve static and dynamic content.
*/
#include "mylib.h"
#include "serverlib.h"
#include "threadpool.h"
extern Thread_Pool *pool;
int main(int argc, char **argv)
{
int listenfd, connfd, port, num_threads;
socklen_t clientlen;
struct sockaddr_in clientaddr;
/* Check command line args */
if (argc != 3) {
fprintf(stderr, "usage: %s <port> <num_threads>\n", argv[0]);
exit(1);
}
port = atoi(argv[1]);
num_threads = atoi(argv[2]);
listenfd = Open_listenfd(port);
if(listenfd == -1){
perror("Open_listenfd");
exit(-1);
}
TP_Init(num_threads);
while (1) {
clientlen = sizeof(clientaddr);
connfd = Accept(listenfd, (SA *)&clientaddr, &clientlen); //line:netp:tiny:accept
fprintf(stderr, "client %d connected\n", connfd);
if(connfd > 0)
TP_Add_Woker(doit, &connfd);
//doit(connfd); //line:netp:tiny:doit
//Close(connfd); //line:netp:tiny:close
}
}