Skip to content

Commit

Permalink
Add a test for the TCP_USER_TIMEOUT option. (#1192)
Browse files Browse the repository at this point in the history
* Add a test for the TCP_USER_TIMEOUT option.
* Explicitly set errno to ENOTSUP on unsupported OS's
  • Loading branch information
michael-grunder authored Jun 1, 2023
1 parent 5cbd1f2 commit ded32c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ded32c7

Please sign in to comment.