forked from unpbook/unpv13e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchild02l.c
40 lines (32 loc) · 783 Bytes
/
child02l.c
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
#include "unp.h"
pid_t
child_make(int i, int listenfd, int addrlen)
{
pid_t pid;
void child_main(int, int, int);
if ( (pid = Fork()) > 0)
return(pid); /* parent */
child_main(i, listenfd, addrlen); /* never returns */
}
void
child_main(int i, int listenfd, int addrlen)
{
int connfd;
void web_child(int);
fd_set rset;
socklen_t clilen;
struct sockaddr *cliaddr;
cliaddr = Malloc(addrlen);
printf("child %ld starting\n", (long) getpid());
FD_ZERO(&rset);
for ( ; ; ) {
FD_SET(listenfd, &rset);
Select(listenfd+1, &rset, NULL, NULL, NULL);
if (FD_ISSET(listenfd, &rset) == 0)
err_quit("listenfd readable");
clilen = addrlen;
connfd = Accept(listenfd, cliaddr, &clilen);
web_child(connfd); /* process the request */
Close(connfd);
}
}