Class 21: Homework
You must print this sheet out and write/type
answers on it! Also print
out the server code with line
numbers to refer to in your answers.
Look through the complete TCP server code linked at the
bottom of these notes. Right now, if I started the server
and 300 people all tried to connect at once, some of those
people would simply fail to connect. What would have to
change in the server code to ensure that all 300 of those
connection requests would be accepted eventually, rather
than simply lost in the ether?
The accept system call returns a
descriptor sessionfd.
-
Explain the purpose of the
descriptor
sessionfd
and how it's different from the descriptor sfd.
-
Immediately after the call to fork(), the
parent process closes the descriptor
sessionfd. At what line does
this happen?
- Why is it that, immediately after the call to fork(), the
parent process closes that descriptor?
What would have to be done to change this program to
work as a single multi-threaded process, rather than
multiple processes?
In what situations might you prefer to write a TCP
server as a single multi-threaded process rather than
multiple processes?