From 3f503b6f2ba5e89f67cdb6dc79dbec55e11485ce Mon Sep 17 00:00:00 2001 From: michael-grunder Date: Tue, 30 May 2023 14:24:46 -0700 Subject: [PATCH 1/2] Add a test for the TCP_USER_TIMEOUT option. --- test.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test.c b/test.c index f3cb73434..51c9e18a3 100644 --- a/test.c +++ b/test.c @@ -409,10 +409,19 @@ static void test_tcp_options(struct config cfg) { redisContext *c; c = do_connect(cfg); + test("We can enable TCP_KEEPALIVE: "); test_cond(redisEnableKeepAlive(c) == REDIS_OK); - disconnect(c, 0); +#ifdef TCP_USER_TIMEOUT + test("We can set TCP_USER_TIMEOUT: "); + test_cond(redisSetTcpUserTimeout(c, 100) == REDIS_OK); +#else + test("Setting TCP_USER_TIMEOUT errors when unsupported: "); + test_cond(redisSetTcpUserTimeout(c, 100) == REDIS_ERR && c->err == REDIS_ERR_IO); +#endif + + redisFree(c); } static void test_reply_reader(void) { From d37d592f5b063f0e05526d7a14267594eceea92d Mon Sep 17 00:00:00 2001 From: michael-grunder Date: Wed, 31 May 2023 11:15:36 -0700 Subject: [PATCH 2/2] Explicitly set errno to ENOTSUP on unsupported OS's --- net.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net.c b/net.c index 3968acc84..1e016384f 100644 --- a/net.c +++ b/net.c @@ -234,6 +234,7 @@ int redisContextSetTcpUserTimeout(redisContext *c, unsigned int timeout) { res = setsockopt(c->fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, sizeof(timeout)); #else res = -1; + errno = ENOTSUP; (void)timeout; #endif if (res == -1) {