On the other hand if the request is for dynamic

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: r **argv) { int listenfd, *connfdp, port, clientlen; struct sockaddr_in clientaddr; pthread_t tid; if (argc != 2) { fprintf(stderr, "usage: %s <port>\n", argv[0]); exit(0); } port = atoi(argv[1]); listenfd = open_listenfd(port); while (1) { clientlen = sizeof(clientaddr); connfdp = Malloc(sizeof(int)); *connfdp = Accept(listenfd, (SA *) &clientaddr, &clientlen); Pthread_create(&tid, NULL, thread, connfdp); } } /* thread routine */ void *thread(void *vargp) { int connfd = *((int *)vargp); Pthread_detach(pthread_self()); Free(vargp); echo_r(connfd); /* reentrant version of echo() */ Close(connfd); return NULL; } code/net/echoservert.c Figure 12.35: Concurrent echo server based on threads. 644 #include "csapp.h" ssize t readline r(Rline *rptr); CHAPTER 12. NETWORK PROGRAMMING returns: number of bytes read (0 if EOF), -1 on error The readline function takes as input an Rline structure shown in Figure 12.36. The first three members correspond to the arguments that users pass to readline. The next three...
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