summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2022-08-30 11:44:01 +0800
committerMichael Grunder <michael.grunder@gmail.com>2022-09-02 10:25:52 -0700
commitfce8abc1c19ab731f5c84797aa71b4d49921913f (patch)
treece362bac272df3eb6c7ef1039110f830a12f2f90
parentcfb6ca881132f7d44121935f55493e144511fbb6 (diff)
Introduce .close method for redisContextFuncs
Currently, hiredis supports TCP/SSL/Unix, all of the connection types use a single FD(int), close() is enough to close a connection. For the further step, introduce .close method for redisContextFuncs, this allows to close a complex connection context, for example RDMA. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
-rw-r--r--hiredis.c10
-rw-r--r--hiredis.h1
-rw-r--r--ssl.c2
3 files changed, 11 insertions, 2 deletions
diff --git a/hiredis.c b/hiredis.c
index a3b3edd..8b9ceca 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -48,6 +48,7 @@ extern int redisContextUpdateConnectTimeout(redisContext *c, const struct timeva
extern int redisContextUpdateCommandTimeout(redisContext *c, const struct timeval *timeout);
static redisContextFuncs redisContextDefaultFuncs = {
+ .close = redisNetClose,
.free_privctx = NULL,
.async_read = redisAsyncRead,
.async_write = redisAsyncWrite,
@@ -729,7 +730,10 @@ static redisContext *redisContextInit(void) {
void redisFree(redisContext *c) {
if (c == NULL)
return;
- redisNetClose(c);
+
+ if (c->funcs && c->funcs->close) {
+ c->funcs->close(c);
+ }
sdsfree(c->obuf);
redisReaderFree(c->reader);
@@ -766,7 +770,9 @@ int redisReconnect(redisContext *c) {
c->privctx = NULL;
}
- redisNetClose(c);
+ if (c->funcs && c->funcs->close) {
+ c->funcs->close(c);
+ }
sdsfree(c->obuf);
redisReaderFree(c->reader);
diff --git a/hiredis.h b/hiredis.h
index 41cab2d..5969368 100644
--- a/hiredis.h
+++ b/hiredis.h
@@ -245,6 +245,7 @@ typedef struct {
} while(0)
typedef struct redisContextFuncs {
+ void (*close)(struct redisContext *);
void (*free_privctx)(void *);
void (*async_read)(struct redisAsyncContext *);
void (*async_write)(struct redisAsyncContext *);
diff --git a/ssl.c b/ssl.c
index 887e1fe..a05b898 100644
--- a/ssl.c
+++ b/ssl.c
@@ -32,6 +32,7 @@
#include "hiredis.h"
#include "async.h"
+#include "net.h"
#include <assert.h>
#include <errno.h>
@@ -579,6 +580,7 @@ static void redisSSLAsyncWrite(redisAsyncContext *ac) {
}
redisContextFuncs redisContextSSLFuncs = {
+ .close = redisNetClose,
.free_privctx = redisSSLFree,
.async_read = redisSSLAsyncRead,
.async_write = redisSSLAsyncWrite,