Question: In Linux systems, typing Ctrl+D indicates EOF on standard input. What happens if you type Ctrl+D to the program in Figure 12.6 while it is
In Linux systems, typing Ctrl+D indicates EOF on standard input. What happens if you type Ctrl+D to the program in Figure 12.6 while it is echoing each line of the client?
Figure 12.6

1 #include "csapp.h" void echo(int connfd); 2 void command (void); 3 4 5 6 7 8 9 10 11 NENSCHRANNARS5 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 int main(int argc, charargv) { } int listenfd, connfd; socklen_t clientlen; struct sockaddr_storage clientaddr: fd set read set, ready_set; } 11 (arge 2) { fprintf(stderr, "usage: %s ", argv[0]); exit(0); } 11stenfd Open_11stenfd(argv[1]); /* Clear read set */ FD_ZERO (&read_set); FD_SET(STDIN_FILENO, &read_set); / Add stdin to read set / FD_SET(11stenfd, read_set): /* Add listenfd to read set / while (1) { ready set read_set; Select(11stenfd+1, ready_set, NULL, NULL, NULL); 11 (FD ISSET (STDIN_FILENO, &ready_set)) command(); /* Read command line from stdin / 11 (FD_ISSET (11stenfd, ready_set)) { clientlen - sizeof(struct sockaddr_storage); connfd Accept (listenfd, (SA)&clientaddr, &clientlen); echo (connfd); /* Echo client input until EOF ./ Close (connfd); void command (void) { char bur [MAXLINE]: if (!Fgeta (buf, MAXLINE, stdin)) exit(0); /* EDF +/ printf("%s", buf); /* Process the input command /
Step by Step Solution
3.34 Rating (160 Votes )
There are 3 Steps involved in it
Recall that the echo function from Figure 1122 echoes eac... View full answer
Get step-by-step solutions from verified subject matter experts
