From 14403a8f632dd87960c3ef3a866c15c14c922dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 8 Mar 2024 11:28:00 +0100 Subject: [PATCH] unix,tcp: allow 0 delay in uv_tcp_keepalive The removed check was introduced in https://github.com/libuv/libuv/pull/4272 but it breaks previously working (and documented) behavior: https://nodejs.org/api/net.html#socketsetkeepaliveenable-initialdelay --- src/unix/tcp.c | 3 --- test/test-tcp-flags.c | 8 +++++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/unix/tcp.c b/src/unix/tcp.c index 799fca77..f8bafd66 100644 --- a/src/unix/tcp.c +++ b/src/unix/tcp.c @@ -467,9 +467,6 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) { if (!on) return 0; - if (delay == 0) - return -1; - #ifdef __sun /* The implementation of TCP keep-alive on Solaris/SmartOS is a bit unusual * compared to other Unix-like systems. diff --git a/test/test-tcp-flags.c b/test/test-tcp-flags.c index 30178d70..e16a2b2c 100644 --- a/test/test-tcp-flags.c +++ b/test/test-tcp-flags.c @@ -33,7 +33,7 @@ TEST_IMPL(tcp_flags) { loop = uv_default_loop(); - r = uv_tcp_init(loop, &handle); + r = uv_tcp_init_ex(loop, &handle, AF_INET); ASSERT_OK(r); r = uv_tcp_nodelay(&handle, 1); @@ -42,6 +42,12 @@ TEST_IMPL(tcp_flags) { r = uv_tcp_keepalive(&handle, 1, 60); ASSERT_OK(r); + r = uv_tcp_keepalive(&handle, 0, 0); + ASSERT_OK(r); + + r = uv_tcp_keepalive(&handle, 1, 0); + ASSERT_OK(r); + uv_close((uv_handle_t*)&handle, NULL); r = uv_run(loop, UV_RUN_DEFAULT);