summaryrefslogtreecommitdiff
path: root/hiredis.h
diff options
context:
space:
mode:
authorMichael Grunder <michael.grunder@gmail.com>2020-07-29 11:53:03 -0700
committerGitHub <noreply@github.com>2020-07-29 11:53:03 -0700
commitd8ff72387d5474e56228a3403dc91354d9916189 (patch)
tree1a6fa645967132b78d92d52de9c9175b429236ba /hiredis.h
parentbe32bcdc8e84ae7dc091ceeffca2c5d4126f415c (diff)
Move SSL management to a distinct private pointer. (#855)
We need to allow our users to use redisContext->privdata as context for any RESP3 PUSH messages, which means we can't use it for managing SSL connections. Bulletpoints: * Create a secondary redisContext member for internal use only called privctx and rename the redisContextFuncs->free_privdata accordingly. * Adds a `free_privdata` function pointer so the user can tie allocated memory to the lifetime of a redisContext (like they can already do with redisAsyncContext) * Enables SSL tests in .travis.yml
Diffstat (limited to 'hiredis.h')
-rw-r--r--hiredis.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/hiredis.h b/hiredis.h
index 1a6bf0b..de442ab 100644
--- a/hiredis.h
+++ b/hiredis.h
@@ -196,6 +196,10 @@ typedef struct {
redisFD fd;
} endpoint;
+ /* Optional user defined data/destructor */
+ void *privdata;
+ void (*free_privdata)(void *);
+
/* A user defined PUSH message callback */
redisPushFn *push_cb;
redisAsyncPushFn *async_push_cb;
@@ -213,8 +217,12 @@ typedef struct {
(opts)->type = REDIS_CONN_UNIX; \
(opts)->endpoint.unix_socket = path;
+#define REDIS_OPTIONS_SET_PRIVDATA(opts, data, dtor) \
+ (opts)->privdata = data; \
+ (opts)->free_privdata = dtor; \
+
typedef struct redisContextFuncs {
- void (*free_privdata)(void *);
+ void (*free_privctx)(void *);
void (*async_read)(struct redisAsyncContext *);
void (*async_write)(struct redisAsyncContext *);
ssize_t (*read)(struct redisContext *, char *, size_t);
@@ -250,8 +258,14 @@ typedef struct redisContext {
struct sockadr *saddr;
size_t addrlen;
- /* Additional private data for hiredis addons such as SSL */
+ /* Optional data and corresponding destructor users can use to provide
+ * context to a given redisContext. Not used by hiredis. */
void *privdata;
+ void (*free_privdata)(void *);
+
+ /* Internal context pointer presently used by hiredis to manage
+ * SSL connections. */
+ void *privctx;
/* An optional RESP3 PUSH handler */
redisPushFn *push_cb;