Modifiche varie per i test delle situazioni limite
[gapil.git] / sources / TCP_echod.c
index d75fd1febc6000fdec5c3dba2cd13a5b0e2755ab..049155744c919942c335a3a5f3b818ce0005990f 100644 (file)
@@ -26,7 +26,7 @@
  *
  * Usage: echod -h give all info
  *
- * $Id: TCP_echod.c,v 1.6 2003/06/19 13:29:03 piccardi Exp $ 
+ * $Id: TCP_echod.c,v 1.8 2003/07/27 14:28:19 piccardi Exp $ 
  *
  ****************************************************************/
 /* 
@@ -41,6 +41,7 @@
 #include <syslog.h>      /* syslog system functions */
 #include <signal.h>      /* signal functions */
 #include <errno.h>       /* error code */
+#include <string.h>      /* error code */
 #include "Gapil.h"
 
 #define BACKLOG 10
@@ -183,8 +184,9 @@ void usage(void) {
     printf("Usage:\n");
     printf("  echod [-h] \n");
     printf("  -h          print this help\n");
-    printf("  -d          print debug info\n");
+    printf("  -d          write debug info\n");
     printf("  -i          use interactively\n");
+    printf("  -w N        wait N sec. before calling accept\n");
     exit(1);
 }
 /*
@@ -197,7 +199,25 @@ void ServEcho(int sockfd) {
     int size;
     /* 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);
+           }
+       }
        nwrite = FullWrite(sockfd, buffer, nread);
+       if (nwrite < 0) {
+           snprintf(debug, MAXLINE+20, "Errore in scrittura: %s \n", 
+                    strerror(errno));
+           if (demonize) {          /* daemon mode */
+               syslog(LOG_DEBUG, debug);
+           } else {
+               printf("%s", debug);
+           }       
+       }
        if (debugging) {
            buffer[nread] = 0;
            snprintf(debug, MAXLINE+20, "Letti %d byte, %s", nread, buffer);