Monday, September 5, 2011

setsockopt : Setting Socket Options


Knowing that the size of the sending and receiving buffers for the default socket are quite large, you as an application designer might decide that a smaller set of buffers might be more appropriate. This might be especially significant if you are expecting several  instances of the program to run on your system.

Options are set on sockets using the setsockopt(2) function. Its function prototype is given as follows:

#include <sys/types.h>
#include <sys/socket.h>

int setsockopt(int s,
               int level,
               int optname,
               const void *optval,
               socklen_t optlen);

This function closely resembles the getsockopt(2) function discussed earlier. The arguments for setsockopt(2) are listed as follows:
  1. The socket s to effect an option change upon.
  2. The socket level of the option.
  3. The option optname to set.
  4. The pointer optval to the value to be used for the new option value.
  5. The option value length optlen, in bytes.

The only real difference between this function's arguments and the getsockopt(2) argument list is that the last argument is passed by value only. It is an input value only in this case.

No comments:

Post a Comment