getsockopt (socket, option)
setsockopt (socket, option, value1, value2? = nil)
getsockopt returns the socket option value(s) on success, as shown below, or nil on failure. When the option has two values, they are returned as a list.
setsockopt returns 0 on success, otherwise -1.
These functions get and set a socket option, using the socket's file descriptor. The supported socket options are given below.
![]() | SO_SNDTIMEO, SO_RCVTIMEO, SO_SNDLOWAT and SO_RCVLOWAT are not supported by all operating systems. |
| Option | Possible Values | Comments |
|---|---|---|
| SO_BROADCAST | 0 for off, non-zero for on. | Allows for broadcasting datagrams from the socket. |
| SO_DEBUG | 0 for off, non-zero for on. | Records debugging information. |
| SO_DONTROUTE | 0 for off, non-zero for on. | Sends messages directly to the network interface instead of using normal message routing. |
| SO_ERROR | A number. | Resets the error status (for getsockopt only). |
| SO_KEEPALIVE | 0 for off, non-zero for on. | Transmits messages periodically on a connected socket. No response means the connection is broken. |
| SO_LINGER | Two values: on_or_off and linger_time, where on_or_off is 0 for off, non-zero for on. If on, a value for linger_time is required. | Keeps the socket open after a close() call, to deliver untransmitted messages. If on_or_off is non-zero, the socket will block for the duration of the linger_time or until all messages have been sent. |
| TCP_NODELAY | 0 for enable, non-zero for disable. | Disables the Nagle algorithm for sending data. |
| SO_OOBINLINE | 0 for off, non-zero for on. | Puts out-of-band data in the normal input queue. |
| SO_REUSEADDR | 0 for off, non-zero for on. | Permits the reuse of local addresses for this socket. |
| SO_RCVBUF | A number. | The size of the input buffer. |
| SO_RCVLOWAT | A number. | Sets the minimum count for input operations. |
| SO_RCVTIMEO | Two values: seconds and nanoseconds. | Sets a timeout value for input. |
| SO_SNDBUF | A number. | The size of the output buffer. |
| SO_SNDLOWAT | A number. | Sets the minimum count for output operations. |
| SO_SNDTIMEO | Two values: seconds and nanoseconds. | Sets a timeout value for output. |
| SO_TYPE | A number. | The type of socket (for getsockopt only). |
Copyright © 1995-2006 by Cogent Real-Time Systems, Inc. All rights reserved.