658 chapter 12 network programming codenettinytinyc 1

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: memory resources will be reclaimed when it terminates (line 32), and we must free the memory block that was allocated by the main thread (line 33). Finally, the thread routine calls the echo r function (line 35) before terminating in line 37. So why do we call echo r instead of the trusty echo function? The echo function calls the readline function (Figure 12.16, which in turn calls the my read function (Figure 12.16), which maintains three static variables, and thus is not reentrant. Since my read is not reentrant, neither are readline or echo. To build a correct threaded echo server, we must use a reentrant version of echo called echo r, which is based on the readline r function, a reentrant version of the readline function developed by Stevens [77]. 12.6. CONCURRENT SERVERS 643 code/net/echoservert.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include "csapp.h" void echo_r(int connfd); void *thread(void *vargp); int main(int argc, cha...
View Full Document

Ask a homework question - tutors are online