Error void bindint sockfd struct sockaddr myaddr 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: .c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 void serve_dynamic(int fd, char *filename, char *cgiargs) { char buf[MAXLINE]; /* return first part of HTTP response */ sprintf(buf, "HTTP/1.0 200 OK\r\n"); Writen(fd, buf, strlen(buf)); sprintf(buf, "Server: Tiny Web Server\r\n"); Writen(fd, buf, strlen(buf)); if (Fork() == 0) { /* child */ /* real server would set all CGI vars here */ setenv("QUERY_STRING", cgiargs, 1); Dup2(fd, STDOUT_FILENO); /* redirect output to client */ Execve(filename, NULL, environ); /* run CGI program */ } Wait(NULL); /* parent reaps child */ } code/net/tiny/tiny.c Figure 12.52: T INY serve dynamic: Serves dynamic content to a client. After sending the first part of the response, we fork a new child process (line 11). The child initializes the QUERY STRING environment variable with the CGI arguments from the request URI (line 13). Notice that a real server would set the other CGI environment variables here as well. For brevity, we have omitted this step. Next, the child redirects the child’s standard output to the connected file descriptor (line 14), and then loads and runs the CGI program (line 15). Since the CGI program runs in th...
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