
Concept explainers
Explanation of Solution
Implementation of a concurrent version of the TINY web server on I/O threads:
Modified “main.c” code:
#include "csapp.h"
//Function declaration
void doit(int fd);
void read_requesthdrs(rio_t *rp);
int parse_uri(char *uri, char *filename, char *cgiargs);
void serve_static(int fd, char *filename, int filesize);
void get_filetype(char *filename, char *filetype);
void serve_dynamic(int fd, char *filename, char *cgiargs);
void clienterror(int fd, char *cause, char *errnum,char *shortmsg, char *longmsg);
void *thread(void *vargp);
//Main function
int main(int argc, char **argv)
{
//Declare variable
int listenfd, connfd;
int *connfdp;
pthread_t tid;
char hostname[MAXLINE], port[MAXLINE];
socklen_t clientlen;
struct sockaddr_storage clientaddr;
/* Check the command line argument. if the argument does not satify, then */
if (argc != 2)
{
//Display the below error message
fprintf(stderr, "usage: %s <port>\n", argv[0]);
fprintf(stderr, "use default port 5000\n");
listenfd = Open_listenfd("5000");
}
//Otherwise,
else
{
//Call the Open_listenfd method
listenfd = Open_listenfd(argv[1]);
}
//Check condition
while (1)
{
//Get the length the client address
clientlen = sizeof(clientaddr);
//For connection accept
connfd = Accept(listenfd, (SA *)&clientaddr, &clientlen);
//Call the method
Getnameinfo((SA *) &clientaddr, clientlen, hostname, MAXLINE,
port, MAXLINE, 0);
//Display the accepted connection
printf("Accepted connection from (%s, %s)\n", hostname, port);
connfdp = (int*)Malloc(sizeof(int));
*connfdp = connfd;
//Call Pthread_create method
Pthread_create(&tid, NULL, thread, connfdp);
}
}
//Function definition for thread method
void *thread(void *vargp)
{
//Compute the connection file descriptor number
int connfd = *(int*)vargp;
//Call pthread detach method
Pthread_detach(Pthread_self());
//Free the given file
Free(vargp);
//Call doit method
doit(connfd);
//Close the connection
Close(connfd);
return NULL;
}
/* Function definition for doit method that is for handle HTTP request or response transfer */
void doit(int fd)
{
//Declare variable
int is_static;
struct stat sbuf;
char buf[MAXLINE], method[MAXLINE], uri[MAXLINE], version[MAXLINE];
char filename[MAXLINE], cgiargs[MAXLINE];
//Create object for rio function
rio_t rio;
/* Read request line and headers */
Rio_readinitb(&rio, fd);
//Check read request
if (!Rio_readlineb(&rio, buf, MAXLINE))
return;
//Display the buffer
printf("%s", buf);
//Display the parse request
sscanf(buf, "%s %s %s", method, uri, version);
//Check condition
if (strcasecmp(method, "GET"))
{
//Call client error method
clienterror(fd, method, "501", "Not Implemented","Tiny does not implement this method");
return;
}
//Call read_requestdrs method
read_requesthdrs(&rio);
/* Parse URI from GET request */
is_static = parse_uri(uri, filename, cgiargs);
//Check the static connection
if (stat(filename, &sbuf) < 0)
{
//Call client error method
clienterror(fd, filename, "404", "Not found",
"Tiny couldn't find this file");
return;
}
/* Check serve static content */
if (is_static)
{
if (!(S_ISREG(sbuf.st_mode)) || !(S_IRUSR & sbuf.st_mode))
{
//Call client error method
clienterror(fd, filename, "403", "Forbidden","Tiny couldn't read the file");
return;
}
//Call serve_static method
serve_static(fd, filename, sbuf.st_size);
}
//Otherwise check the serve dynamic content
else
{
if (!(S_ISREG(sbuf.st_mode)) || !(S_IXUSR & sbuf.st_mode))
{
//Call client error method
clienterror(fd, filename, "403", "Forbidden","Tiny couldn't run the CGI program");
return;
}
//Call serve dynamic method
serve_dynamic(fd, filename, cgiargs);
}
}
/* Function definition for read_requestdrs that is for read HTTP request headers */
void read_requesthdrs(rio_t *rp)
{
//Declare variable
char buf[MAXLINE];
Rio_readlineb(rp, buf, MAXLINE);
printf("%s", buf);
//Check condition
while(strcmp(buf, "\r\n"))
{
//Call rio readlineb function
Rio_readlineb(rp, buf, MAXLINE);
printf("%s", buf);
}
return;
}
/* Function definition for parse uri into file nane and cgi argument */
int parse_uri(char *uri, char *filename, char *cgiargs)
{
//Declare char variable
char *ptr;
//Check content type...

Want to see the full answer?
Check out a sample textbook solution
Chapter 12 Solutions
EBK COMPUTER SYSTEMS
- I want to explain my work in Python botnets and it is completely working on the tkinter function with an explanation of how I can work on it with an introduction about what it is and what its benefit isarrow_forwardWhen you connect your device to Wi-Fi, what happens "under the hood"? Explain in detail, with pictures, what it's like.arrow_forwardYou will write a program that allows the user to keep track of college locations and details about each location. To begin you will create a College python class that keeps track of the csollege's unique id number, name, address, phone number, maximum students, and average tuition cost. Once you have built the College class, you will write a program that stores College objects in a dictionary while using the College's unique id number as the key. The program should display a menu in this order that lets the user: 1) Add a new College 2) Look up a College 4) Delete an existing College 5) Change an existing College's name, address, phone number, maximum guests, and average tuition cost. 6) Exit the programarrow_forward
- I need help with this problem and an step by step explanation of the solution from the image described below. (Introduction to Signals and Systems)arrow_forwardI need help with this problem and an step by step explanation of the solution from the image described below. (Introduction to Signals and Systems)arrow_forwardI need help with this problem and an step by step explanation of the solution from the image described below. (Introduction to Signals and Systems)arrow_forward
- I need help with this problem and an step by step explanation of the solution from the image described below. (Introduction to Signals and Systems)arrow_forwardHello, Please read the provided text carefully—everything is detailed there. I need high-quality diagrams for both cases: Student A and Student B, showing the teacher teaching them through knowledge distillation. Each case should be represented as a separate image. The knowledge distillation process must be clearly illustrated in both. I’ve attached an image that shows the level of clarity I’m aiming for. Please do not use AI-generated diagrams. If I wanted that, I could do it myself using ChatGPT Premium. I’m looking for support from a real human expert—and I know you can help. " 1. Teacher Model Architecture (T) Dataset C: Clean data with complete inputs and labels Architecture Input Embedding Layer Converts multivariate sensor inputs into dense vectors. Positional Encoding Adds time-step order information to each embedding. Transformer Encoder Stack (repeated N times) Multi-Head Self-Attention: Captures temporal dependencies across time steps. Add…arrow_forward(connection)? Q1: Define the BGP ? Ebgp vs I bgp, and how do I advertise? With a drawing example QT: Explain how to make messages in the BGP protocol. Q: What is concept the hot potato routing in BGP? Q: What are the criteria for BGP route selection? Qo: Define the concept of Spanning Tree Protocol. Explain in detail and draw the figures. Q1: What happens when STP is disabled? QV: Define the concept of broadcast storm. QA: List and explain the Steps to a Loop-Free Topology when using the Spanning Tree Algorithm and Spanning Tree Protocol in a four-step process. I want a typical and concise Solutionarrow_forward
- WATCH THE VIDEO ABOUT MODELLING OR SPECIFICATION PHASE AND ANSWER THE FOLLOWING QUESTIONS: https://www.youtube.com/watch?v=uoIxDeAyfdo 1.- DEFINE SPECIFICATION OR MODELLING 2.- WRITE DOWN THE 3 REQUIREMENTS SPECIFICATION TECHNIQUES OR FORMATS 3.-DEFINE USE CASES 4.-DEFINE SRS 5.-DEFINE USER STORIES 6.- IS IT RECOMMENDABLE TO USE SRS DOCUMENTS IN AGILE METHODOLOGY? WHY? 7.- HOW DO YOU KNOW WHICH TECHNIQUE OR FORMAT TO USE? 8.- WRITE DOWN THE USE CASE COMPONENTSarrow_forwardREADING AND LISTENING ACTIVITIES BASED ON THE VIDEO: “REQUIREMENT ELICITATION “ Watch the following video and look for the answer to the following questions: https://www.youtube.com/watch?v=pSQRetBoaRE&t=24s 1.-NAME THE 2 PHASES OF THE REQUIREMENT ENGINEERING PROCESS 2.-NAME AT LEAST 7 ELICITATION TECHNIQUES TO COLLECT THE INFORMATION REQUIRED 3.-REFER TO THE NUMBER OF QUESTIONS AND TYPE OF QUESTIONS THAT SHOULD BE ASKED TO THE DIFFERENT STAKEHOLDERS. 4.-NAME THE DIFFERENT TYPES OF PROBLEMS YOU CAN ENCOUNTER DURING THE REQUIREMENT ELICITATION PROCESS 5.- ACCORDING TO THE VIDEO, WHICH TYPES OF TECHNIQUES SHOULD YOU USE, WHICH ONES WOULD YOU USE ACCORDING TO PROFESSOR SHERRIFF ‘S RECOMMENDATIONS?arrow_forwardCan you please show me how I can do this on google sheets. For the spreadsheet you need to create a multi page sheets thing that uses all the techniques of counts/sums and graph showing how many contracts have been returned for each grade...you can make up the data (let's say in grade 9 I got 15 contracted back with fake data that I want you to show me how to create on google spreadsheet) For grade 10 i got 20 contracts signed, for grade 11 I got 16 contracts and for grade 12 I got 25 contracts back. Can you help me pls. Thanks so much. Make sure you have graphs on the page and also the sum written as a formula and the numbers filled in the columns.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





