Ancora correzioni sulle varie versioni di server.
[gapil.git] / listati / TCP_echod_second.c
1 int main(int argc, char *argv[])
2 {
3     ...
4     ...
5     if (waiting) sleep(waiting);
6     /* handle echo to client */
7     while (1) {
8         /* accept connection */
9         while (((conn_fd = accept(list_fd, (struct sockaddr *)&cli_add, &len)) 
10                 < 0) && (errno == EINTR)); 
11         if ( conn_fd < 0) {
12             PrintErr("accept error");
13             exit(1);
14         }
15         if (debugging) {
16             inet_ntop(AF_INET, &cli_add.sin_addr, ipaddr, sizeof(ipaddr));
17             snprintf(debug, MAXLINE, "Accepted connection form %s\n", ipaddr);
18             if (demonize) {
19                 syslog(LOG_DEBUG, debug);
20             } else {
21                 printf("%s", debug);
22             }
23         }
24         /* fork to handle connection */
25         ...
26         ...
27     }
28 }