0 posixerrorrc pthreadcondbroadcast error void

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: e from file name */ void get_filetype(char *filename, char *filetype) { if (strstr(filename, ".html")) strcpy(filetype, "text/html"); else if (strstr(filename, ".gif")) strcpy(filetype, "image/gif"); else if (strstr(filename, ".jpg")) strcpy(filetype, "image/jpg"); else strcpy(filetype, "text/plain"); } code/net/tiny/tiny.c Figure 12.51: T INY serve static: Serves static content to a client. 12.8. PUTTING IT TOGETHER: THE TINY WEB SERVER Failing to do this would introduce a potentially fatal memory leak. 661 Line 18 performs the actual transfer of the file to the client. The writen function copies the filesize bytes starting at location srcp (which of course is mapped to the requested file) to the client’s connected descriptor. Finally, line 19 frees the mapped virtual memory area. This is important to avoid a potentially fatal memory leak. The serve dynamic Function T INY serves any type of dynamic content by forking a child process, and then running a CGI program in the context of the child. The serve dynamic function in Figure 12.52 begins by sending a response line indicating success to the client (lines 6-7), along with an informational Server header (lines 8-9). The CGI program is responsible for sending the rest of the response. Notice that this is not as robust as we might wish, since it doesn’t allow for the possibility that the CGI program might encounter some error. code/net/tiny/tiny...
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