[ Team LiB ] Previous Section Next Section

Chapter 16

16.1

The descriptor is shared between the parent and child, so it has a reference count of 2. If the parent calls close, this just decrements the reference count from 2 to 1, and since it is still greater than 0, a FIN is not sent. This is another reason for the shutdown function: to force a FIN to be sent even if the descriptor's reference count is greater than 0.

16.2

The parent will keep writing to the socket that has received a FIN, and the first segment sent to the server will elicit an RST in response. The next write after this will send SIGPIPE to the parent as we discussed in Section 5.12.

16.3

When the child calls getppid to send SIGTERM to the parent, the returned PID will be 1, the init process, which inherits all children whose parents terminate while their children are still running. The child will try to send the signal to the init process, but will not have adequate permission. But if there is a chance that this client could run with superuser privileges, allowing it to send this signal to init, then the return value of getppid should be tested before sending the signal.

16.4

If these two lines are removed, select is called. But select will return immediately because with the connection established, the socket is writable. This test and goto are to avoid the unnecessary call to select.

16.5

This can happen when the server immediately sends data when its accept returns, and when the client host is busy when the second packet of the three-way handshake arrives to complete the connection at the client end (Figure 2.5). SMTP servers, for example, immediately write to a new connection before reading from it, to send a greeting message to the client.


    [ Team LiB ] Previous Section Next Section