Turns TCP keep-alive probes on s on or off and returns whether it worked.
With keepalive false the probes are switched off and the timings are ignored. When it is true, each timing that is
above zero replaces the system default: seconds of idleness before the first probe, seconds between probes, and the
number of unanswered probes before the connection is dropped. Zero keeps the system's value. A failure is logged through
context.logger and returns false; options already set stay set.
Winsock counts the two timings in milliseconds; they are converted from seconds here. The probe count is applied only where the system has the option (Windows 10 and later) and is otherwise left at the system's own.
assert(socket_init());
s := socket(AF_INET, .SOCK_STREAM, .TCP);
defer close_and_reset(*s);
assert(set_keepalive(s, true));
assert(set_keepalive(s, true, 30, 5, 4));
assert(set_keepalive(s, false));Doesn't run in the browser (skipped on wasm).
set_keepalive :: (
s: Socket,
keepalive: bool,
idle_seconds_before_keepalive: s32 = 0,
keepalive_interval_seconds: s32 = 0,
num_keepalive_attempts: s32 = 0
) -> bool
Parameters
- s: Socket
- keepalive: bool
- idle_seconds_before_keepalive: s32 = 0
- keepalive_interval_seconds: s32 = 0
- num_keepalive_attempts: s32 = 0
Returns
- bool
set_keepalive :: (
s: Socket,
keepalive: bool,
idle_seconds_before_keepalive: s32 = 0,
keepalive_interval_seconds: s32 = 0,
num_keepalive_attempts: s32 = 0
) -> bool
Turns TCP keep-alive probes on s on or off. WASI has no socket options, so this is false, with the error ENOSYS
(and the failure logged).
Parameters
- s: Socket
- keepalive: bool
- idle_seconds_before_keepalive: s32 = 0
- keepalive_interval_seconds: s32 = 0
- num_keepalive_attempts: s32 = 0
Returns
- bool
set_keepalive :: (
s: Socket,
keepalive: bool,
idle_seconds_before_keepalive: s32 = 0,
keepalive_interval_seconds: s32 = 0,
num_keepalive_attempts: s32 = 0
) -> bool
Turns TCP keep-alive probes on s on or off and returns whether it worked.
With keepalive false the probes are switched off and the timings are ignored. When it is true, each timing that is
above zero replaces the system default: seconds of idleness before the first probe, seconds between probes, and the
number of unanswered probes before the connection is dropped. Zero keeps the system's value. A failure is logged through
context.logger and returns false; options already set stay set.
Parameters
- s: Socket
- keepalive: bool
- idle_seconds_before_keepalive: s32 = 0
- keepalive_interval_seconds: s32 = 0
- num_keepalive_attempts: s32 = 0
Returns
- bool
assert(socket_init());
s := socket(AF_INET, .SOCK_STREAM, .TCP);
defer close_and_reset(*s);
assert(set_keepalive(s, true));
assert(set_keepalive(s, true, 30, 5, 4));
assert(set_keepalive(s, false));Doesn't run in the browser (skipped on wasm).