#include <oskit/net/socket.h>oskit_error_t oskit_socket_getsockopt(oskit_socket_t *s, oskit_u32_t level, oskit_u32_t name, [out] void *val, [in/out] oskit_size_t *valsize);
oskit_error_t oskit_socket_setsockopt(oskit_socket_t *s, oskit_u32_t level, oskit_u32_t name, const void *val, oskit_size_t valsize);
getsockopt and setsockopt manipulate the options associated with a socket. Options may exist at multiple protocol levels.
- s
- The socket whose options are to be queried or set.
- level
- When manipulating socket options the level at which the option resides and the name of the option must be specified. To manipulate options at the socket level, level is specified as OSKIT_SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate protocol controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to IPPROTO_TCP.
- name
- name and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. Definitions for socket level options are described below. Options at other protocol levels vary in format and name.
Most socket-level options utilize an int parameter for val. For setsockopt, the parameter should be non-zero to enable a boolean option, or zero if the option is to be disabled. OSKIT_SO_LINGER uses a struct oskit_linger parameter, which specifies the desired state of the option and the linger interval (see below). OSKIT_SO_SNDTIMEO and OSKIT_SO_RCVTIMEO use a struct timeval parameter, defined in <oskit/c/sys/time.h>
The following options are recognized at the socket level. Except as noted, each may be examined with getsockopt and set with setsockopt.
OSKIT_SO_DEBUG enables recording of debugging information OSKIT_SO_REUSEADDR enables local address reuse OSKIT_SO_REUSEPORT enables duplicate address and port bindings OSKIT_SO_KEEPALIVE enables keep connections alive OSKIT_SO_DONTROUTE enables routing bypass for outgoing messages OSKIT_SO_LINGER linger on close if data present OSKIT_SO_BROADCAST enables permission to transmit broadcast messages OSKIT_SO_OOBINLINE enables reception of out-of-band data in band OSKIT_SO_SNDBUF set buffer size for output OSKIT_SO_RCVBUF set buffer size for input OSKIT_SO_SNDLOWAT set minimum count for output OSKIT_SO_RCVLOWAT set minimum count for input OSKIT_SO_SNDTIMEO set timeout value for output OSKIT_SO_RCVTIMEO set timeout value for input OSKIT_SO_TYPE get the type of the socket (get only) OSKIT_SO_ERROR get and clear error on the socket (get only) OSKIT_SO_DEBUG enables debugging in the underlying protocol modules. OSKIT_SO_REUSEADDR indicates that the rules used in validating addresses supplied in bind should allow reuse of local addresses. OSKIT_SO_REUSEPORT allows completely duplicate bindings by multiple clients if they all set OSKIT_SO_REUSEPORT before binding the port. This option permits multiple instances of a program to each receive UDP/IP multicast or broadcast datagrams destined for the bound port. OSKIT_SO_KEEPALIVE enables the periodic transmission of messages on a connected socket. Should the connected party fail to respond to these messages, the connection is considered broken and clients using the socket are notified when attempting to send data. OSKIT_SO_DONTROUTE indicates that outgoing messages should bypass the standard routing facilities. Instead, messages are directed to the appropriate network interface according to the network portion of the destination address.
OSKIT_SO_LINGER controls the action taken when unsent messages are queued on a socket and the socket is released. If the socket promises reliable delivery of data and OSKIT_SO_LINGER is set, the system will block on the last release attempt until it is able to transmit the data or until it decides it is unable to deliver the information (a timeout period, termed the linger interval, is specified in the setsockopt call when OSKIT_SO_LINGER is requested. If OSKIT_SO_LINGER is disabled, the last release will succeed immediately. The option OSKIT_SO_BROADCAST requests permission to send broadcast datagrams on the socket. Broadcast was a privileged operation in earlier versions of the system. With protocols that support out-of-band data, the OSKIT_SO_OOBINLINE option requests that out-of-band data be placed in the normal data input queue as received; it will then be accessible with recv or read calls without the OSKIT_MSG_OOB flag. Some protocols always behave as if this option were set.
OSKIT_SO_SNDBUF and OSKIT_SO_RCVBUF are options to adjust the normal buffer sizes allocated for output and input buffers, respectively. The buffer size may be increased for high-volume connections, or may be decreased to limit the possible backlog of incoming data. An absolute limit may be places on these values.
OSKIT_SO_SNDLOWAT is an option to set the minimum count for output operations. Most output operations process all of the data supplied by the call, delivering data to the protocol for transmission and blocking as necessary for flow control. Nonblocking output operations will process as much data as permitted subject to flow control without blocking, but will process no data if flow control does not allow the smaller of the low water mark value or the entire request to be processed.
The default value for OSKIT_SO_SNDLOWAT is set to a convenient size for network efficiency, often 1024.
OSKIT_SO_RCVLOWAT is an option to set the minimum count for input operations. In general, receive calls will block until any (non-zero) amount of data is received, then return with the smaller of the amount available or the amount requested. The default value for OSKIT_SO_RCVLOWAT is 1. If OSKIT_SO_RCVLOWAT is set to a larger value, blocking receive calls normally wait until they have received the smaller of the low water mark value or the requested amount. Receive calls may still return less than the low water mark if an error occurs, a signal is caught, or the type of data next in the receive queue is different than that returned.
OSKIT_SO_SNDTIMEO is an option to set a timeout value for output operations. It accepts a struct timeval parameter with the number of seconds and microseconds used to limit waits for output operations to complete. If a send operation has blocked for this much time, it returns with a partial count or with the error OSKIT_EWOULDBLOCK if no data were sent.
This timer is restarted each time additional data are delivered to the protocol, implying that the limit applies to output portions ranging in size from the low water mark to the high water mark for output.
OSKIT_SO_RCVTIMEO is an option to set a timeout value for input operations. It accepts a struct timeval parameter with the number of seconds and microseconds used to limit waits for input operations to complete.
This timer is restarted each time additional data are received by the protocol, and thus the limit is in effect an inactivity timer. If a receive operation has been blocked for this much time without receiving additional data, it returns with a short count or with the error OSKIT_EWOULDBLOCK if no data were received.
Finally, OSKIT_SO_TYPE and OSKIT_SO_ERROR are options used only with getsockopt. OSKIT_SO_TYPE returns the type of the socket, such as OSKIT_SOCK_STREAM. OSKIT_SO_ERROR returns any pending error on the socket and clears the error status. It may be used to check for asynchronous errors on connected datagram sockets or for other asynchronous errors.
- val, valsize
- The parameters val and valsize are used to access option values for setsockopt. For getsockopt they identify a buffer in which the value for the requested option(s) are to be returned. For getsockopt, valsize initially contains the size of the buffer pointed to by val, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned, val may be NULL.
Returns 0 on success, or an error code specified in <oskit/error.h>, on error.