Continuo a riordinare gli esempi.
[gapil.git] / listati / TCP_echod_second.c
index d5c8bba93c29bd192f8021ec45ca687c036582a6..78557afdb04fd9f9a16e3a9fb406d59b3ac9f1f4 100644 (file)
@@ -1,7 +1,23 @@
 int main(int argc, char *argv[])
 {
     ...
 int main(int argc, char *argv[])
 {
     ...
+    int waiting = 0;
+    int compat = 0;
     ...
     ...
+
+    /* Main code begin here */
+    if (compat) {                             /* install signal handler */
+       Signal(SIGCHLD, HandSigCHLD);         /* non restarting handler */
+    } else {
+       SignalRestart(SIGCHLD, HandSigCHLD);  /* restarting handler */
+    }
+    ...
+
+    /* main body */
+    if (listen(list_fd, BACKLOG) < 0 ) {
+       PrintErr("listen error");
+       exit(1);
+    }
     if (waiting) sleep(waiting);
     /* handle echo to client */
     while (1) {
     if (waiting) sleep(waiting);
     /* handle echo to client */
     while (1) {
@@ -22,7 +38,7 @@ int main(int argc, char *argv[])
            }
        }
        /* fork to handle connection */
            }
        }
        /* fork to handle connection */
-        ...
        ...
     }
        ...
     }
+    return;
 }
 }