Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pid_t pid;
- int listenfd, connfd;
- listenfd = Socket(...);
- /* fill in sockaddr_in{} with server's well-known port */
- Bind(listenfd, ...);
- Listen(listenfd, LISTENQ);
- for (;;) {
- connfd = Accept(listenfd, ...); /* probably blocks */
- if ((pid = Fork()) == 0) {
- Close(listenfd); /* child closes listening socket */
- doit(connfd); /* process the request */
- Close(connfd); /* done with this client */
- exit(0); /* child terminates */
- }
- Close(connfd); /* parent closes connected socket */
- }
Advertisement
Add Comment
Please, Sign In to add comment