Ancora correzioni sulle varie versioni di server.
[gapil.git] / sources / TCP_echod.c
index 576c47f2069ac3d03bcd2b177af409d20f9c9bdb..25a457187e4d000071e59623967d67938163a216 100644 (file)
@@ -26,7 +26,7 @@
  *
  * Usage: echod -h give all info
  *
- * $Id: TCP_echod.c,v 1.7 2003/06/19 14:18:27 piccardi Exp $ 
+ * $Id: TCP_echod.c,v 1.10 2003/07/29 22:41:36 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 strings */
 #include "Gapil.h"
 
 #define BACKLOG 10
@@ -103,7 +104,7 @@ int main(int argc, char *argv[])
      * 
      * ***********************************************************/
     /* install SIGCHLD handler */
-    Signal(SIGCHLD, HandSigCHLD);  /* establish handler */
+    SignalRestart(SIGCHLD, HandSigCHLD);  /* establish handler */
     /* create socket */
     if ( (list_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        perror("Socket creation error");
@@ -198,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) {
+           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);
@@ -215,8 +234,8 @@ void ServEcho(int sockfd) {
  * routine to print error on stout or syslog
  */
 void PrintErr(char * error) {
-    if (demonize) {          /* daemon mode */
-       syslog(LOG_ERR, error);
+    if (demonize) {                       /* daemon mode */
+       syslog(LOG_ERR, "%s: %m", error); /* log string and error message */
     } else {
        perror(error);
     }