Page #443 (Chapter 25)


Chapter 26

26.1

In the fork example, there will be 101 descriptors in use, one listening socket, and 100 connected sockets. But each of the 101 processes (one parent, 100 children) has just one descriptor open (ignoring any others, such as standard input, if the server is not daemonized). In the threaded server, however, there are 101 descriptors in the single process. Each thread (including the main thread) is handling one descriptor.

26.2

The final two segments of the TCP connection termination ”the server's FIN and the client's ACK of this FIN ”will not be exchanged. This leaves the client's end of the connection in the FIN_WAIT_2 state (Figure 2.4). Berkeley-derived implementations will time out the client's end when it remains in this state for just over 11 minutes (pp.825 “827 of TCPv2). The server will also run out of descriptors (eventually).

26.3

This message should be printed by the main thread when it reads an EOF from the socket and the other thread is still running. A simple way to do this is to declare another external named done that is initialized to 0. Before the thread copyto returns, it sets this variable to 1. The main thread checks this variable, and if 0, prints the error message. Since only one thread sets the variable, there is no need for any synchronization.




UNIX Network Programming Volume 1, Third Edition
Unix Network Programming, Volume 1: The Sockets Networking API (3rd Edition)
ISBN: 0131411551
EAN: 2147483647
Year: 2003
Pages: 441

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net