Merge branch 'master' of ssh://gapil.gnulinux.it/srv/git/gapil
[gapil.git] / listati / ServEcho_second.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 (nread < 0) {
8             PrintErr("Errore in lettura");
9             return;
10         }
11         nwrite = FullWrite(sockfd, buffer, nread);
12         if (nwrite) {
13             PrintErr("Errore in scrittura");
14             return;
15         }
16         if (debugging) {
17             buffer[nread] = 0;
18             snprintf(debug, MAXLINE+20, "Letti %d byte, %s", nread, buffer);
19             if (demonize) {          /* daemon mode */
20                 syslog(LOG_DEBUG, debug);
21             } else {
22                 printf("%s", debug);
23             }
24         }
25     }
26     return;
27 }