|[ Team LiB ]|
The first version of our echo client/server totaled about 150 lines (including the readline and writen functions), yet provided lots of details to examine. The first problem we encountered was zombie children and we caught the SIGCHLD signal to handle this. Our signal handler then called waitpid and we demonstrated that we must call this function instead of the older wait function, since Unix signals are not queued. This led us into some of the details of POSIX signal handling (additional information on this topic is provided in Chapter 10 of APUE).
The next problem we encountered was the client not being notified when the server process terminated. We saw that our client's TCP was notified, but we did not receive that notification since we were blocked, waiting for user input. We will use the select or poll function in Chapter 6 to handle this scenario, by waiting for any one of multiple descriptors to be ready, instead of blocking on a single descriptor.
We also discovered that if the server host crashes, we do not detect this until the client sends data to the server. Some applications must be made aware of this fact sooner; in Section 7.5, we will look at the SO_KEEPALIVE socket option.
Our simple example exchanged lines of text, which was okay since the server never looked at the lines it echoed. Sending numeric data between the client and server can lead to a new set of problems, as shown.
|[ Team LiB ]|