Modifiche al server di echo per introdurre le stampe di debugging e la
[gapil.git] / listati / ServEcho.c
index 917c7c4d00c4b5497ee26fb2bbf7a791b6765853..0ea06359a7907d3364180a883f8be0b7ab385da5 100644 (file)
@@ -1,10 +1,19 @@
 void ServEcho(int sockfd) {
     char buffer[MAXLINE];
     int nread, nwrite;
-    
+    char debug[MAXLINE+20];
     /* main loop, reading 0 char means client close connection */
     while ( (nread = read(sockfd, buffer, MAXLINE)) != 0) {
-        nwrite = FullWrite(sockfd, buffer, nread);
+       if (debugging) {
+           snprintf(debug, MAXLINE+20, "Letti %d bytes, %s\n", nread, buffer);
+           debug[strlen(debug)] = 0;
+           if (demonize) {          /* go daemon */
+               syslog(LOG_DEBUG, debug);
+           } else {
+               fputs(debug, stdout);
+           }
+       }
+       nwrite = FullWrite(sockfd, buffer, nread);
     }
     return;
 }