Risistemate le trattazioni delle opzioni SO_KEEPALIVE e SO_REUSEADDR, con
[gapil.git] / listati / TCP_echod_fourth.c
diff --git a/listati/TCP_echod_fourth.c b/listati/TCP_echod_fourth.c
new file mode 100644 (file)
index 0000000..5eb9d30
--- /dev/null
@@ -0,0 +1,20 @@
+int main(int argc, char *argv[])
+{
+/* 
+ * Variables definition  
+ */
+    int list_fd, conn_fd;
+    int waiting = 0;
+    int keepalive = 0;
+    ...
+    ...        
+
+       if (pid == 0) {      /* child */
+           close(list_fd);          /* close listening socket */   
+           if (keepalive) {         /* enable keepalive ? */
+               setsockopt(conn_fd, SOL_SOCKET, SO_KEEPALIVE, 
+                          &keepalive, sizeof(keepalive));
+           }
+           ServEcho(conn_fd);       /* handle echo */
+           ...
+}