Risistemato tutto il primo esempio di server echo e le funzioni FullWrite e
[gapil.git] / listati / ServEcho_first.c
diff --git a/listati/ServEcho_first.c b/listati/ServEcho_first.c
new file mode 100644 (file)
index 0000000..1cda55c
--- /dev/null
@@ -0,0 +1,13 @@
+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 (nwrite) {
+           PrintErr("write error");
+       }
+    }
+    return;
+}