SO_KEEPALIVE

The state of the SO_KEEPALIVE socket option determines whether keep-alive packets are sent on a connection-oriented socket. This socket option applies only to listening sockets and connection-oriented sockets.

To set the state of this socket option, a WSK application calls the WskControlSocket function with the following parameters.

Parameter Value

RequestType

WskSetOption

ControlCode

SO_KEEPALIVE

Level

SOL_SOCKET

InputSize

sizeof(ULONG)

InputBuffer

A pointer to a ULONG-typed variable that contains the value for the new state of the socket option:

  • 0: Disable sending keep-alive packets

  • 1: Enable sending keep-alive packets

OutputSize

0

OutputBuffer

NULL

OutputSizeReturned

NULL

To retrieve the state of this socket option, a WSK application calls the WskControlSocket function with the following parameters.

Parameter Value

RequestType

WskGetOption

ControlCode

SO_KEEPALIVE

Level

SOL_SOCKET

InputSize

0

InputBuffer

NULL

OutputSize

sizeof(ULONG)

OutputBuffer

A pointer to a ULONG-typed variable that receives the value of the state of the socket option:

  • 0: Sending keep-alive packets is disabled

  • 1: Sending keep-alive packets is enabled

OutputSizeReturned

NULL

A WSK application must specify a pointer to an IRP when calling the WskControlSocket function to set or retrieve the state of the SO_KEEPALIVE socket option.

The default state of this socket option is that sending keep-alive packets is disabled.

If this socket option is enabled on a listening socket, all incoming connections that are accepted on that listening socket have this socket option enabled by default. A WSK application can call the WskControlSocket function on an accepted socket to override the state of this socket option that was inherited from the listening socket.

Keep-alive packets are sent by the underlying network transport. Not all network transports support sending keep-alive packets.

For more information about using keep-alive packets, see RFC 1122, section 4.2.3.6, "TCP Keep-Alives".

Requirements

Version

Available in Windows Vista and later versions of the Windows operating systems.

Header

Ws2def.h (include Wsk.h)