18.5 UICI Implementations of Different Server StrategiesProgram 4.6 on page 100 to perform the actual copying. Once it has finished the copying, the server closes the communication file descriptor, displays the number of bytes copied, and resumes listening. Program 18.1 server.cA serial server implemented using UICI.
Exercise 18.9Under what circumstances does a client cause the server in Program 18.1 to terminate?Answer:The server executes the first return statement if it is not started with a single command-line argument. The u_open function creates a communication endpoint associated with a port number. The u_open function fails if the port is invalid, if the port is in use, or if system resources are not available to support the request. At this point, no clients are involved. Once the server has reached u_accept, it does not terminate unless it receives a signal. A client on a remote machine cannot cause the server to terminate. A failure of u_accept causes the server to loop and try again. Notice that I/O errors cause copyfile to return, but these errors do not cause server termination.Program 18.2 implements the parent-server strategy. The parent accepts client connections and forks a child to call copyfile so that the parent can resume waiting for connections. Because the child receives a copy of the parent's environment at the time of the fork, it has access to the private communication channel represented by communfd. Exercise 18.10What happens if the client name does not fit in the buffer passed to u_accept?Answer:The implementation of u_accept does not permit the name to overflow the buffer. Instead, u_accept truncates the client name. (See Section 18.7.6.) Exercise 18.11What happens if after the connection is made, you enter text at standard input of the server?Answer:The server program never reads from standard input, and what you type at standard input is not sent to the remote machine. Exercise 18.12Program 18.2 uses r_close and r_waitpid from the restart library. How does this affect the behavior of the program?Answer:Functions in the restart library restart the corresponding function when the return value is 1 and errno is EINTR. This return condition occurs when the signal handler of a caught signal returns. Program 18.2 does not catch any signals, so using the restarted versions is not necessary. We use the functions from the restart library to make it easier to add signal handling capability to the programs. Program 18.2 serverp.cA server program that forks a child to handle communication.
|