SOSetSockOpt

Syntax

#include <cafe.h>
#include <cafe/network.h>

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

Parameters

s Descriptor of the socket.
level Protocol level at which the option resides. Supported levels:
  • SOL_SOCKET
  • IPPROTO_IP
  • IPPROTO_TCP
optname Socket level options (SOL_SOCKET)
SO_REUSEADDR Allow local address reuse. get/set
SO_KEEPALIVE keep connections alive get/set
SO_DONTROUTE Use interface addresses. get/set
SO_BROADCAST Permit sending of broadcast msgs (currently not supported). get/set
SO_LINGER Linger on close if data present. get/set
SO_OOBINLINE Leave received OOB data in line. get/set
SO_TCPSACK Allow TCP SACK (Selective acknowledgment). get/set
SO_SNDBUF Send buffer size. get/set
SO_RCVBUF Receive buffer size. get/set
SO_LASTERROR Get error status and clear. get
SO_TYPE Get socket type. get
SO_MAXMSG TCP_MSS (max segment size) (currently not supported). get/set
SO_RXDATA Get count of bytes in the socket receive buffer. get
SO_TXDATA Get count of bytes in the socket send buffer. get
SO_MYADDR Get my IP address (for connected socket). get
SO_NBIO Set socket into NON-blocking mode. set
SO_BIO Set socket into blocking mode. set
SO_NONBLOCK Set/get blocking mode via optval param. get/set
SO_WINSCALE Enable/disable window scaling. get/set
SO_KEEPIDLE Time before keepalive probes begin. get/set
SO_KEEPINTVL Interval between probes. get/set
SO_KEEPCNT Number of probes before connection is dropped. get/set
SO_RUSRBUF Indicates the system to use receive buffer in application's memory. get/set

IP level options (IPPROTO_IP)
IP_TTL IP packet time to live. get/set
IP_TOS IP packet Type Of Service. get/set

TCP level options (IPPROTO_TCP)
TCP_ACKDELAYTIME Set time for delayed ACKs. get/set
TCP_NOACKDELAY Suppress delayed ACKs. get/set
TCP_ACKFREQUENCY Number of TCP ACKs that will be outstanding before delayed ACK timer is ignored. get/set
TCP_MAXSEG TCP maximum segment size (currently not supported). get/set
TCP_NODELAY Enable/Disable Nagle Algorithm. get/set
optval Value to set.
optlen Length of the optval in bytes.

For all socket level options (SOL_SOCKET) except for SO_BIO, SO_NBIO length must be at least 4 bytes (for SO_LINGER length must be at least sizeof(struct linger)).

For TCP level options, (IPPROTO_TCP)length must be at least 4 bytes.

Return Values

0 upon success. Upon failure, -1 is returned and errno is set appropriately.

Errors

SO_ELIBNOTREADY Socket library is not initialized.
SO_ENOMEM Insufficient memory in the stack.
SO_EINVAL Specified argument is invalid.
SO_ENOTSOCK The argument fd does not refer to a socket.
SO_ENOTCONN Specified fd is not in the connected state.
SO_ENOBUFS Could not prepare memory for RCV/SND buffer.
SO_ENOPROTOOPT The option is unknown at the level indicated.
SO_EBUSY Socket resource manager busy processing requests.
SO_EABORTED Indicates the operation was aborted. For example, this error can be returned for calls blocked on a socket after the socket is closed by another thread.
SO_EUNKNOWN Unknown error.

Description

Applies the given value to the specified option for socket s.

Socket level options (SOL_SOCKET)

IP level options (IPPROTO_IP)

TCP level options (IPPROTO_TCP)

Do Not Call From

Callbacks Do not call this function from any callback function.
Interrupt handler Do not call this function from any interrupt handler.
Exception handler Do not call this function from any exception handler.

See Also

SOGetSockOpt

Revision History

2014/07/03 Added SO_RUSRBUF.
2013/11/21 Added descriptions about SO_KEEPIDLE, SO_KEEPINTVL, and SO_KEEPCNT.
2013/05/16 Clarified socket buffer size details in SO_SNDBUF, SO_RCVBUF.
2012/10/09 Updated Errors section.
2012/09/21 Updated description about SO_TCPSACK.
2012/09/18 Updated description about SO_SNDBUF, SO_RCVBUF.
2012/09/07 Added detailed information of optname.
2012/09/06 Cleanup pass.
2012/08/16 Added new option (SO_WINSCALE) and related description.
2012/02/07 Added description in SO_TXDATA.
2011/10/04 Removed unsupported options (SO_BIGCWND, SO_FULLMSS, SO_SNDLOWAT, SO_RCVLOWAT).
2011/10/04 Explicitly indicated which options are supported for only set or get.
2011/09/20 Mentioned the options, level, minimum required length of optval.
2011/07/11 Added Errors section.
2011/04/21 Changed argument type of the optlen from pointer to value.
2011/02/21 Initial version.


CONFIDENTIAL