NetSock_OptSet

Set the specified socket option to the sock_id socket.

Files

net_sock.h/net_sock.c

Prototype

          NET_SOCK_RTN_CODE_ID NetSock_OptSet(NET_SOCK_ID        sock_id,
                                              NET_SOCK_PROTOCOL  level,
                                              NET_SOCK_OPT_NAME  opt_name,
                                              void              *p_opt_val,
                                              NET_SOCK_OPT_LEN   opt_len,
                                              NET_ERR           *p_err);

Arguments

sock_id

This is the socket ID returned by NetSock_Open()/socket() when the socket was created or by NetSock_Accept()/accept() when a connection was accepted.

level

Protocol level from which to set the socket option.

opt_name

Name of the option to set.

p_opt_val

Pointer to the value to set the socket option.

opt_len

Option length.

p_err

Pointer to variable that will receive the return error code from this function:

NET_SOCK_ERR_NONE
NET_SOCK_ERR_INVALID_DATA_SIZE
NET_SOCK_ERR_NULL_PTR
NET_SOCK_ERR_INVALID_OPT

Returned Value

NET_SOCK_BSD_ERR_NONE/0, if successful;

NET_SOCK_BSD_ERR_OPT_SET/-1, otherwise.

Required Configuration

None.

Notes / Warnings

The supported options are:

  • Protocol level NET_SOCK_PROTOCOL_SO:
    • NET_SOCK_OPT_SOCK_KEEP_ALIVE
    • NET_SOCK_OPT_SOCK_TX_BUF_SIZE / NET_SOCK_OPT_SOCK_RX_BUF_SIZE
    • NET_SOCK_OPT_SOCK_TX_TIMEOUT / NET_SOCK_OPT_SOCK_RX_TIMEOUT
  • Protocol level NET_SOCK_PROTOCOL_IP:
    • NET_SOCK_OPT_IP_TOS
    • NET_SOCK_OPT_IP_TTL
  • Protocol level NET_SOCK_PROTOCOL_TCP:
    • NET_SOCK_OPT_TCP_NO_DELAY
    • NET_SOCK_OPT_TCP_KEEP_CNT
    • NET_SOCK_OPT_TCP_KEEP_IDLE
    • NET_SOCK_OPT_TCP_KEEP_INTVL

This function must be called after either listen() (in the server case) or connect() (in the client case) have been called.