Sets options on a socket. The $QIO equivalent is the IO$_SETMODE function. Format #include <types.h> #include <socket.h> int setsockopt ( int s, int level, int optname, char *optval, int optlen ); (_DECC_V4_SOURCE) int setsockopt ( int s, int level, int optname, const void *optval, size_t optlen ); (not_DECC_V4_SOURCE)
1 – Arguments
s A socket descriptor created by the socket() function. level The protocol level for which the socket options are to be modified. It can have one of the following values: SOL_SOCKET Set the options at the socket level. p Any protocol number. Set the options for protocol level p. For IPv4, see the IN.H header file for the IPPROTO values. For IPv6, see the IN6.H header file for the IPPROTO_IPV6 values. optname Interpreted by the protocol specified in level. Options at each protocol level are documented with the protocol. Refer to: o Socket Options for a list of socket options o TCP Protocol Options for a list of TCP options o IP Protocol Options for a list of IP options optval Points to a buffer containing the arguments of the specified option. All socket-level options other than SO_LINGER should be nonzero if the option is to be enabled, or zero if it is to be disabled. SO_LINGER uses a linger structure argument defined in the SOCKET.H header file. This structure specifies the desired state of the option and the linger interval. The option value for the SO_LINGER command is the address of a linger structure. If the socket is type SOCK_STREAM, which promises the reliable delivery of data, and l_onoff is nonzero, the system blocks the process on the close() attempt until it is able to transmit the data or until it decides it is unable to deliver the information. A timeout period, called the linger interval, is specified in l_ linger. If l_onoff is set to zero and a close() is issued, the system processes the close in a manner that allows the process to continue as soon as possible. optlen An integer specifying the size of the buffer pointed to by optval.
2 – Description
This function manipulates options associated with a socket. Options can exist at multiple protocol levels. They are always present at the uppermost socket level. When manipulating socket options, specify the level at which the option resides and the name of the option. To manipulate options at the socket level, specify the value of level as SOL_SOCKET. To manipulate options at any other level, supply the protocol number of the appropriate protocol controlling the option. For example, to indicate that an option is to be interpreted by TCP, set the value for the level argument to the protocol number (IPPROTO_TCP) of TCP. For IPv4, see the IN.H header file for the various IPPROTO values. For IPv6, see the IN6.H header file for the various IPPROTO_IPV6 values.
3 – Return Values
0 Successful completion. -1 Error; errno is set to indicate the error.
4 – Errors
EACCES The calling process does not have appropriate permissions. EBADF The descriptor is invalid. EDOM The send and receive timeout values are too large to fit in the timeout fields of the socket structure. EINVAL The optlen argument is invalid. EISCONN The socket is already connected; the specified option cannot be set when the socket is in the connected state. EFAULT The optval argument is not in a readable part of the user address space. ENOBUFS The system had insufficient resources to complete the call. ENOPROTOOPT The option is unknown. ENOTSOCK The socket descriptor is invalid. EFAULT The optname argument is invalid.