From f12d52c1ed4d62b92ffe46aa06b7f082f206f236 Mon Sep 17 00:00:00 2001 From: Mark Nunberg Date: Mon, 15 Apr 2019 07:51:11 -0400 Subject: [PATCH] don't automatically use timeout for read/write timeout with... connectWithTimeout() The timeout value will still be used for I/O if using connectWithOptions() --- hiredis.c | 5 ++++- hiredis.h | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hiredis.c b/hiredis.c index 6f60294..ddc6374 100644 --- a/hiredis.c +++ b/hiredis.c @@ -685,7 +685,9 @@ redisContext *redisConnectWithOptions(const redisOptions *options) { return NULL; } if (options->timeout != NULL && (c->flags & REDIS_BLOCK) && c->fd != REDIS_INVALID_FD) { - redisContextSetTimeout(c, *options->timeout); + if (!(options->options & REDIS_OPT_NORDWRTIMEOUT)) { + redisContextSetTimeout(c, *options->timeout); + } } return c; } @@ -703,6 +705,7 @@ redisContext *redisConnectWithTimeout(const char *ip, int port, const struct tim redisOptions options = {0}; REDIS_OPTIONS_SET_TCP(&options, ip, port); options.timeout = &tv; + options.options |= REDIS_OPT_NORDWRTIMEOUT; return redisConnectWithOptions(&options); } diff --git a/hiredis.h b/hiredis.h index 6e56c5e..efd3e64 100644 --- a/hiredis.h +++ b/hiredis.h @@ -133,6 +133,13 @@ struct redisSsl; */ #define REDIS_OPT_NOAUTOFREE 0x04 +/** + * When using connectWithOptions, have the timeout only apply to the + * initial connect, not subsequent read/write attempts. This option + * is here to support the legacy connectWithTimeout() + */ +#define REDIS_OPT_NORDWRTIMEOUT 0x08 + /* In Unix systems a file descriptor is a regular signed int, with -1 * representing an invalid descriptor. In Windows it is a SOCKET * (32- or 64-bit unsigned integer depending on the architecture), where