--- tiny.origin.c 2017-11-09 02:57:43.651936112 +0000 +++ tiny.6.c 2017-11-09 02:57:43.651936112 +0000 @@ -13,6 +13,8 @@ void clienterror(int fd, char *cause, char *errnum, char *shortmsg, char *longmsg); +void echo(int connfd); + int main(int argc, char **argv) { int listenfd, connfd; @@ -33,11 +35,24 @@ Getnameinfo((SA *) &clientaddr, clientlen, hostname, MAXLINE, port, MAXLINE, 0); printf("Accepted connection from (%s, %s)\n", hostname, port); - doit(connfd); //line:netp:tiny:doit + echo(connfd); Close(connfd); //line:netp:tiny:close } } +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) { + if (strcmp(buf, "\r\n") == 0) + break; + Rio_writen(connfd, buf, n); + } +} + /* * doit - handle one HTTP request/response transaction */