Exercises


6.1

We said that a descriptor set can be assigned to another descriptor set across an equals sign in C. How is this done if a descriptor set is an array of integers? ( Hint : Look at your system's <sys/select.h> or <sys/types.h> header.)

6.2

When describing the conditions for which select returns "writable" in Section 6.3, why did we need the qualifier that the socket had to be nonblocking for a write operation to return a positive value?

6.3

What happens in Figure 6.9 if we prepend the word "else" before the word "if" on line 19?

6.4

In our example in Figure 6.21 add code to allow the server to be able to use as many descriptors as currently allowed by the kernel. ( Hint : Look at the setrlimit function.)

6.5

Let's see what happens when the second argument to shutdown is SHUT_RD . Start with the TCP client in Figure 5.4 and make the following changes: Change the port number from SERV_PORT to 19, the chargen server (Figure 2.18); then, replace the call to str_cli with a call to the pause function. Run this program specifying the IP address of a local host that runs the chargen server. Watch the packets with a tool such as tcpdump (Section C.5). What happens?

6.6

Why would an application call shutdown with an argument of SHUT_RDWR instead of just calling close ?

6.7

What happens in Figure 6.22 when the client sends an RST to terminate the connection?

6.8

Recode Figure 6.25 to call sysconf to determine the maximum number of descriptors and allocate the client array accordingly .




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