Add a test for the TCP_USER_TIMEOUT option. (#1192)

* Add a test for the TCP_USER_TIMEOUT option.
* Explicitly set errno to ENOTSUP on unsupported OS's
This commit is contained in:
Michael Grunder 2023-06-01 09:09:11 -07:00 committed by GitHub
parent 5cbd1f2960
commit ded32c7d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

1
net.c
View File

@ -234,6 +234,7 @@ int redisContextSetTcpUserTimeout(redisContext *c, unsigned int timeout) {
res = setsockopt(c->fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, sizeof(timeout)); res = setsockopt(c->fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, sizeof(timeout));
#else #else
res = -1; res = -1;
errno = ENOTSUP;
(void)timeout; (void)timeout;
#endif #endif
if (res == -1) { if (res == -1) {

11
test.c
View File

@ -409,10 +409,19 @@ static void test_tcp_options(struct config cfg) {
redisContext *c; redisContext *c;
c = do_connect(cfg); c = do_connect(cfg);
test("We can enable TCP_KEEPALIVE: "); test("We can enable TCP_KEEPALIVE: ");
test_cond(redisEnableKeepAlive(c) == REDIS_OK); 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) { static void test_reply_reader(void) {