The SockSetSockOpt() call sets options associated with a socket.
>>--SockSetSockOpt(socket, level, optName, optVal)-----------------------><
is the socket descriptor.
specifies which option level is set. The only supported level is SOL_SOCKET.
is the name of a specified socket option.
is the variable containing the data needed by the set command. It is optional.
SockSetSockOpt() sets options associated with a socket with descriptor socket such as enabling debugging at the socket or protocol level, controlling timeouts, or permitting socket data broadcasting. Options can exist at the socket or the protocol level. They are always present at the highest socket level. When setting socket options, the option level and name must be specified.
For socket options that are toggles, the option is enabled if optval is nonzero and disabled if optval is 0.
The following options are recognized for SOL_SOCKET:
enables datagram sockets to broadcast messages. The application can then send broadcast messages using datagram socket, if the interface specified in the destination supports broadcasting of packets.
enables debug information to be recorded for a socket.
enables the socket to bypass the routing of outgoing messages. Outgoing messages are then directed to the network interface specified in the network portion of the destination address. When enabled, packets can only be sent to directly connected networks.
enables stream sockets to send keepalive packets, which keep the connection alive. TCP uses a timer called the keepalive timer. This timer monitors idle connections that might have been disconnected because of a peer crash or timeout. If this option is enabled, a keepalive packet is periodically sent to the peer.
This option is mainly used to enable servers to close connections that are no longer active as a result of clients ending connections without properly closing them.
enables stream sockets to linger on close if data is present. If this option is enabled and there is data still to be sent when SockSoClose() is called, the calling application is blocked during the SockSoClose() call until the data is transmitted or the connection has timed out. If this option is disabled, the SockSoClose() call returns without blocking the caller while TCP is trying to send the data. Although the data transfer is usually successful, it cannot be guaranteed because TCP tries to send the data only for a specific amount of time.
enables stream sockets to receive out-of-band data, which is a logically separate data path using the same connection as the normal data path. If this option is enabled, out-of-band data is placed in the normal data input queue as it is received. It is then made available to SockRecv() and SockRecvFrom() without the MSG_OOB flag being specified in those calls. If this option is disabled, out-of-band data is placed in the priority data input queue as it is received. It can then only be made available to SockRecv() and SockRecvFrom() by specifying the MSG_OOB flag in those calls.
sets the buffer size for input. This option sets the size of the receive buffer to the value contained in the buffer pointed to by optval. In this way, the buffer size can be tailored for specific application needs, such as increasing the buffer size for high-volume connections.
sets the receive low-water mark.
sets the timeout value for a receive operation.
enables stream and datagram sockets to reuse local addresses. Local addresses that are already in use can then be bound. This alters the normal algorithm used in the SockBind() call. At connection time, the system checks whether the local addresses and ports differ from foreign addresses and ports. If not, the error value EADDRINUSE is returned.
Sets the buffer size for output. This option sets the size of the send buffer to the value contained in the buffer pointed to by optval. In this way, the send buffer size can be tailored for specific application needs, such as increasing the buffer size for high-volume connections.
sets the send low-water mark. This mark is ignored for nonblocking calls and not used in the Internet domain.
sets the timeout value for a send operation.
bypasses hardware where possible.
Except for SO_LINGER, all values are integral. SO_LINGER expects two blank delimited integers:
The l_onoff value. It is set to 0 if the SO_LINGER option is disabled.
the l_linger value. The l_linger field specifies the amount of time, in seconds, to be lingered on close. A value of 0 causes SockSoClose() to wait until disconnection completes.
The value 0 indicates successful execution of the call. The value -1 indicates an error. You can get the specific error code SockSock_Errno() or SockPSock_Errno(). Possible values are:
The address is already in use.
socket is not a valid socket descriptor.
optname is not recognized.
There is no buffer space available.
Note: SockSetSockOpt() interfaces with the C function setsockopt().