Modifiche al server di echo per introdurre le stampe di debugging e la
[gapil.git] / listati / ServEcho.c
1 void ServEcho(int sockfd) {
2     char buffer[MAXLINE];
3     int nread, nwrite;
4     char debug[MAXLINE+20];
5     /* main loop, reading 0 char means client close connection */
6     while ( (nread = read(sockfd, buffer, MAXLINE)) != 0) {
7         if (debugging) {
8             snprintf(debug, MAXLINE+20, "Letti %d bytes, %s\n", nread, buffer);
9             debug[strlen(debug)] = 0;
10             if (demonize) {          /* go daemon */
11                 syslog(LOG_DEBUG, debug);
12             } else {
13                 fputs(debug, stdout);
14             }
15         }
16         nwrite = FullWrite(sockfd, buffer, nread);
17     }
18     return;
19 }