Name struct hostent gethostbyaddrconst char addr int

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 12.47 handles one HTTP transaction. First, we read and parse the request line (lines 9-10). Notice that we are using the robust readline function from Figure 12.16 to read the request line. T INY only supports the GET method. If the client requests another method (such as POST), we send it an error message and return to the main routine (lines 11-15), which then closes the connection and awaits the next connection request. Otherwise, we read and (as we shall see) ignore any request headers (line 16). Next, we parse the URI into a filename and a possibly empty CGI argument string, and we set a flag that indicates whether the request is for static or dynamic content (line 19). If the file does not exist on disk, we immediately send an error message to the client and return (lines 20-24). Finally, if the request is for static content (lines 26), we verify that the file is a regular file (i.e., not a directory file or a FIFO) and that we have read permission (line 27). If so, we serve the static content (line 32) to the client. Similarly, if the request is for dynamic content (line 34), we verify that the file is executable (line 35), and if so we go ahead and serve the dynamic content (line 40). 12.8. PUTTING IT TOGETHER: THE TINY WEB SERVER 655 code/net/tiny/tiny.c 1 2 3 4 5 6 7 8 9 10 11 12 13...
View Full Document

Ask a homework question - tutors are online