Corretto echo per un errore nel settaggio di SO_LINGER, immesso
[gapil.git] / sources / TCP_echod.c
index fe14ea31f2f9657c74765335c136057927cd7e22..fd51f982797a745c6d5d2f1e8fc1cf3c5949b45d 100644 (file)
@@ -26,7 +26,7 @@
  *
  * Usage: echod -h give all info
  *
- * $Id: TCP_echod.c,v 1.11 2003/08/02 19:54:11 piccardi Exp $ 
+ * $Id: TCP_echod.c,v 1.12 2003/08/03 18:12:47 piccardi Exp $ 
  *
  ****************************************************************/
 /* 
@@ -176,6 +176,14 @@ int main(int argc, char *argv[])
        if (pid == 0) {      /* child */
            close(list_fd);          /* close listening socket */   
            ServEcho(conn_fd);       /* handle echo */
+           if (debugging) {
+               snprintf(debug, MAXLINE, "Closed connection %s\n", ipaddr);
+               if (demonize) {
+                   syslog(LOG_DEBUG, debug);
+               } else {
+                   printf("%s", debug);
+               }
+           }
            exit(0);
        } else {             /* parent */
            close(conn_fd);          /* close connected socket */
@@ -208,23 +216,13 @@ void ServEcho(int sockfd) {
     /* main loop, reading 0 char means client close connection */
     while ( (nread = read(sockfd, buffer, MAXLINE)) != 0) {
        if (nread < 0) {
-           snprintf(debug, MAXLINE+20, "Errore in lettura: %s \n", 
-                    strerror(errno));
-           if (demonize) {          /* daemon mode */
-               syslog(LOG_DEBUG, debug);
-           } else {
-               printf("%s", debug);
-           }
+           PrintErr("Errore in lettura");
+           return;
        }
        nwrite = FullWrite(sockfd, buffer, nread);
        if (nwrite) {
-           snprintf(debug, MAXLINE+20, "Errore in scrittura: %s \n", 
-                    strerror(errno));
-           if (demonize) {          /* daemon mode */
-               syslog(LOG_DEBUG, debug);
-           } else {
-               printf("%s", debug);
-           }       
+           PrintErr("Errore in scrittura");
+           return;
        }
        if (debugging) {
            buffer[nread] = 0;