5 the csappc source file 297 298 299 300 301 302 303

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: opying the contents of the requested file to the connected descriptor fd (lines 15-19). The code here is somewhat subtle and needs to be studied carefully. Line 15 opens filename for reading and gets its descriptor. In line 16, the Unix mmap function maps the requested file to a virtual memory area. Recall from our discussion of mmap in Section 10.8 that the call to mmap maps the first filesize bytes of file srcfd to a private read-only area of virtual memory that starts at address srcp. Once we have mapped the file to memory, we no longer need its descriptor, so we close the file (line 17). 12.8. PUTTING IT TOGETHER: THE TINY WEB SERVER 659 code/net/tiny/tiny.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 int parse_uri(char *uri, char *filename, char *cgiargs) { char *ptr; if (!strstr(uri, "cgi-bin")) { /* static content */ strcpy(cgiargs, ""); strcpy(filename, "."); strcat(filename, uri); if (uri[strlen(uri)-1] == ’/’) strcat(filename, "home.html"); return 1; } else { /* dynamic content */ ptr = index(uri, ’?’); if (ptr) { strcpy(cgiargs, ptr+1); *ptr = ’\0’; } else strcpy(cg...
View Full Document

Ask a homework question - tutors are online