From d8ff72387d5474e56228a3403dc91354d9916189 Mon Sep 17 00:00:00 2001 From: Michael Grunder Date: Wed, 29 Jul 2020 11:53:03 -0700 Subject: 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 --- test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test.c') diff --git a/test.c b/test.c index 2216ea3..c0eeca7 100644 --- a/test.c +++ b/test.c @@ -49,6 +49,10 @@ struct config { } ssl; }; +struct privdata { + int dtor_counter; +}; + #ifdef HIREDIS_TEST_SSL redisSSLContext *_ssl_ctx = NULL; #endif @@ -786,6 +790,27 @@ static void test_resp3_push_options(struct config config) { redisAsyncFree(ac); } +void free_privdata(void *privdata) { + struct privdata *data = privdata; + data->dtor_counter++; +} + +static void test_privdata_hooks(struct config config) { + struct privdata data = {0}; + redisOptions options; + redisContext *c; + + test("We can use redisOptions to set privdata: "); + options = get_redis_tcp_options(config); + REDIS_OPTIONS_SET_PRIVDATA(&options, &data, free_privdata); + assert((c = redisConnectWithOptions(&options)) != NULL); + test_cond(c->privdata == &data); + + test("Our privdata destructor fires when we free the context: "); + redisFree(c); + test_cond(data.dtor_counter == 1); +} + static void test_blocking_connection(struct config config) { redisContext *c; redisReply *reply; @@ -871,6 +896,8 @@ static void test_blocking_connection(struct config config) { if (major >= 6) test_resp3_push_handler(c); test_resp3_push_options(config); + test_privdata_hooks(config); + disconnect(c, 0); } -- cgit v1.2.3