Gif strcpyfiletype imagegif else if strstrfilename

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ptr) { int n, rc; char c, *ptr = rptr->read_ptr; for (n = 1; n < rptr->read_maxlen; n++) { if ( (rc = my_read_r(rptr, &c)) == 1) { *ptr++ = c; if (c == ’\n’) break; } else if (rc == 0) { if (n == 1) return(0); /* EOF, no data read */ else break; /* EOF, some data was read */ } else return(-1); /* error */ } *ptr = 0; return(n); } code/src/csapp.c Figure 12.38: readline r package: Reentrant version of readline. Adapted from [77]. 646 CHAPTER 12. NETWORK PROGRAMMING Given the reentrant readline r function, we can now create a reentrant version of echo (Figure 12.39) that calls readline r instead of readline. code/net/echo r.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include "csapp.h" void echo_r(int connfd) { size_t n; char buf[MAXLINE]; Rline rline; readline_rinit(connfd, buf, MAXLINE, &rline); while((n = Readline_r(&rline)) != 0) { printf("server received %d bytes\n", n); Writen(connfd, buf, n); } } code/net/echo r.c Figure 12.39: echo r: Reentrant version of echo Discuss...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online