Sunday, August 28, 2011

Using the socket endhostent(3) Function Example


After calling upon sethostent(3) with a value of TRUE, your application might enter a phase of processing where it is known that no further name queries will be required. To use resources in a frugal manner, you need a method to end the connection to the name server, thus freeing the TCP/IP socket that is currently in use. This is the purpose of the endhostent(3) function. Its function synopsis is as follows:

#include <netdb.h>
void endhostent(void);

As you can see, this function takes no arguments and returns no values. The endhostent(3) function can be of significant value to servers, particularly Web servers, where file descriptors are at a premium. You will recall that a socket uses a file descriptor and that one socket is required for each connected client. Server capacity is often restricted by the number of file descriptors that the server can have open. This makes it vitally important for servers to close file descriptors (and sockets) when they are no longer required.

No comments:

Post a Comment