Universidad de Costa RicaEscuela de Ciencias de la Computación e InformáticaCI-0118 Lenguajes ensambladoresMaterial |
|
| ci0118 / material / Bryant-OHallaron / code / 22-netprog2 echo.c | |
/*
* echo - read and echo text lines until client closes connection
*/
/* $begin echo */
#include "csapp.h"
void echo(int connfd)
{
size_t n;
char buf[MAXLINE];
rio_t rio;
Rio_readinitb(&rio, connfd);
while((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0) { //line:netp:echo:eof
printf("server received %d bytes\n", (int)n);
Rio_writen(connfd, buf, n);
}
}
/* $end echo */