The WSPSetSockOpt function sets a socket option.
int WSPSetSockOpt (
SOCKET s,
int level,
int optname,
const char FAR * optval,
int optlen,
LPINT lpErrno
);
WSPSetSockOpt sets the current value for a socket option associated with a socket of any type, in any state. Although options can exist at multiple protocol levels, they are always present at the uppermost "socket'' level. Options affect socket operations, such as whether broadcast messages can be sent on the socket.
There are two types of socket options: Boolean options that enable or disable a feature or behavior, and options which require an integer value or structure. To enable a Boolean option, optval points to a nonzero integer. To disable the option optval points to an integer equal to zero. optlen should be equal to sizeof(int) for Boolean options. For other options, optval points to the an integer or structure that contains the desired value for the option, and optlen is the length of the integer or structure.
level = SOL_SOCKET
Value | Type | Meaning |
---|---|---|
SO_BROADCAST | BOOL | Allow transmission of broadcast messages on the socket. |
SO_DEBUG | BOOL | Record debugging information. |
SO_DONTLINGER | BOOL | Reserved for future use with socket groups: Do not block close waiting for unsent data to be sent. Setting this option is equivalent to setting SO_LINGER with l_onoff set to zero. |
SO_DONTROUTE | BOOL | Do not route: send directly to interface. |
SO_GROUP_PRIORITY | int | Specify the relative priority to be established for sockets that are part of a socket group. |
SO_KEEPALIVE | BOOL | Send keepalives. |
SO_LINGER | struct linger | Linger on close if unsent data is present. |
SO_OOBINLINE | BOOL | Receive out-of-band data in the normal data stream. |
SO_RCVBUF | int | Specify the total per-socket buffer space reserved for receives. This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. |
SO_REUSEADDR | BOOL | Allow the socket to be bound to an address which is already in use. (See bind.) |
SO_SNDBUF | int | Specify the total per-socket buffer space reserved for sends. This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. |
PVD_CONFIG | Service Provider Dependent | This object stores the configuration information for the service provider associated with socket s. The exact format of this data structure is service provider specific. |
Calling WSPGetSockOpt with an unsupported option will result in an error code of WSAENOPROTOOPT being returned in lpErrno.
The WSAENOPROTOOPT error is indicated for non group sockets or for service providers which do not support group sockets.
struct linger {
u_short l_onoff;
u_short l_linger;
}
To enable SO_LINGER, a Windows Sockets SPI client should set l_onoff to a nonzero value, set l_linger to zero or the desired time-out (in seconds), and call WSPSetSockOpt. To enable SO_DONTLINGER (that is, disable SO_LINGER) l_onoff should be set to zero and WSPSetSockOpt should be called. Note that enabling SO_LINGER with a nonzero time-out on a nonblocking socket is not recommended (see section 4.1.7. WSPCloseSocket for details).
Enabling SO_LINGER also disables SO_DONTLINGER, and vice versa. Note that if SO_DONTLINGER is DISABLED (that is, SO_LINGER is ENABLED) then no time-out value is specified. In this case, the time-out used is implementation dependent. If a previous time-out has been established for a socket (by enabling SO_LINGER), then this time-out value should be reinstated by the service provider.
If no error occurs, WSPSetSockOpt returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code is available in lpErrno.
WSAENETDOWN | The network subsystem has failed. |
WSAEFAULT | optval is not in a valid part of the process address space or optlen argument is too small. |
WSAEINPROGRESS | The function is invoked when a callback is in progress. |
WSAEINPROGRESS | A blocking Windows Sockets call is in progress, or the service provider is still processing a callback function. |
WSAEINVAL | level is not valid, or the information in optval is not valid. |
WSAENETRESET | The connection has been broken due to "keep-alive" activity detecting a failure while the operation was in progress. |
WSAENOPROTOOPT | The option is unknown or unsupported for the specified provider. |
WSAENOTCONN | Connection has been reset when SO_KEEPALIVE is set. |
WSAENOTSOCK | The descriptor is not a socket. |
Windows NT: Yes
Windows: Yes
Windows CE: Unsupported.
Header: Declared in ws2spi.h.
WSPBind, WSPGetSockOpt, WSPIoctl, WSPSocket, WSPEventSelect