Ancora correzioni sulle varie versioni di server.
[gapil.git] / listati / TCP_echod_second.c
diff --git a/listati/TCP_echod_second.c b/listati/TCP_echod_second.c
new file mode 100644 (file)
index 0000000..d5c8bba
--- /dev/null
@@ -0,0 +1,28 @@
+int main(int argc, char *argv[])
+{
+    ...
+    ...
+    if (waiting) sleep(waiting);
+    /* handle echo to client */
+    while (1) {
+       /* accept connection */
+       while (((conn_fd = accept(list_fd, (struct sockaddr *)&cli_add, &len)) 
+               < 0) && (errno == EINTR)); 
+       if ( conn_fd < 0) {
+           PrintErr("accept error");
+           exit(1);
+       }
+       if (debugging) {
+           inet_ntop(AF_INET, &cli_add.sin_addr, ipaddr, sizeof(ipaddr));
+           snprintf(debug, MAXLINE, "Accepted connection form %s\n", ipaddr);
+           if (demonize) {
+               syslog(LOG_DEBUG, debug);
+           } else {
+               printf("%s", debug);
+           }
+       }
+       /* fork to handle connection */
+        ...
+       ...
+    }
+}