commit 544cea2: Revert "[Fix] Fix hiredis stupidity" and use the hiredis api as intended
Petr VanÄk
arkamar at atlas.cz
Fri Apr 24 14:14:06 UTC 2020
Author: Petr Vaněk
Date: 2020-03-29 01:06:54 +0100
URL: https://github.com/rspamd/rspamd/commit/544cea204e2f085625b024ea5ad6ff7d0437e1eb (refs/pull/3313/head)
Revert "[Fix] Fix hiredis stupidity" and use the hiredis api as intended
This reverts commit b05b9bf904edce75c17e63982d5e0a82dd3e9064.
---
contrib/hiredis/async.c | 8 +++-----
contrib/hiredis/async.h | 6 ++----
src/libserver/redis_pool.c | 9 ++++-----
3 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/contrib/hiredis/async.c b/contrib/hiredis/async.c
index 851676263..4a2cadf8b 100644
--- a/contrib/hiredis/async.c
+++ b/contrib/hiredis/async.c
@@ -129,7 +129,6 @@ static redisAsyncContext *redisAsyncInitialize(redisContext *c) {
ac->onConnect = NULL;
ac->onDisconnect = NULL;
- ac->disconnectCbdata = NULL;
ac->replies.head = NULL;
ac->replies.tail = NULL;
@@ -216,10 +215,9 @@ int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn
return REDIS_ERR;
}
-int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn, void *cbdata) {
+int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn) {
if (ac->onDisconnect == NULL) {
ac->onDisconnect = fn;
- ac->disconnectCbdata = cbdata;
return REDIS_OK;
}
return REDIS_ERR;
@@ -308,10 +306,10 @@ static void __redisAsyncFree(redisAsyncContext *ac) {
* this context, the status will always be REDIS_OK. */
if (ac->onDisconnect && (c->flags & REDIS_CONNECTED)) {
if (c->flags & REDIS_FREEING) {
- ac->onDisconnect(ac,REDIS_OK,ac->disconnectCbdata);
+ ac->onDisconnect(ac,REDIS_OK);
} else {
c->flags |= REDIS_FREEING;
- ac->onDisconnect(ac,(ac->err == 0) ? REDIS_OK : REDIS_ERR,ac->disconnectCbdata);
+ ac->onDisconnect(ac,(ac->err == 0) ? REDIS_OK : REDIS_ERR);
}
}
diff --git a/contrib/hiredis/async.h b/contrib/hiredis/async.h
index 3d20241c6..59cbf469b 100644
--- a/contrib/hiredis/async.h
+++ b/contrib/hiredis/async.h
@@ -54,7 +54,7 @@ typedef struct redisCallbackList {
} redisCallbackList;
/* Connection callback prototypes */
-typedef void (redisDisconnectCallback)(const struct redisAsyncContext*, int status, void *cbdata);
+typedef void (redisDisconnectCallback)(const struct redisAsyncContext*, int status);
typedef void (redisConnectCallback)(const struct redisAsyncContext*, int status);
/* Context for an async connection to Redis */
@@ -85,8 +85,6 @@ typedef struct redisAsyncContext {
/* Called when either the connection is terminated due to an error or per
* user request. The status is set accordingly (REDIS_OK, REDIS_ERR). */
redisDisconnectCallback *onDisconnect;
- /* Hiredis is just brain-damaged here, need to fix it */
- void *disconnectCbdata;
/* Called when the first write event was received. */
redisConnectCallback *onConnect;
@@ -109,7 +107,7 @@ redisAsyncContext *redisAsyncConnectBindWithReuse(const char *ip, int port,
const char *source_addr);
redisAsyncContext *redisAsyncConnectUnix(const char *path);
int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn);
-int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn, void *cbdata);
+int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn);
void redisAsyncDisconnect(redisAsyncContext *ac);
void redisAsyncFree(redisAsyncContext *ac);
diff --git a/src/libserver/redis_pool.c b/src/libserver/redis_pool.c
index 57fc734f9..2d2510753 100644
--- a/src/libserver/redis_pool.c
+++ b/src/libserver/redis_pool.c
@@ -258,10 +258,9 @@ rspamd_redis_pool_schedule_timeout (struct rspamd_redis_pool_connection *conn)
}
static void
-rspamd_redis_pool_on_disconnect (const struct redisAsyncContext *ac, int status,
- void *ud)
+rspamd_redis_pool_on_disconnect (const struct redisAsyncContext *ac, int status)
{
- struct rspamd_redis_pool_connection *conn = ud;
+ struct rspamd_redis_pool_connection *conn = ac->data;
/*
* Here, we know that redis itself will free this connection
@@ -313,13 +312,13 @@ rspamd_redis_pool_new_connection (struct rspamd_redis_pool *pool,
g_hash_table_insert (elt->pool->elts_by_ctx, ctx, conn);
g_queue_push_head_link (elt->active, conn->entry);
conn->ctx = ctx;
+ ctx->data = conn;
rspamd_random_hex (conn->tag, sizeof (conn->tag));
REF_INIT_RETAIN (conn, rspamd_redis_pool_conn_dtor);
msg_debug_rpool ("created new connection to %s:%d: %p", ip, port, ctx);
redisLibevAttach (pool->event_loop, ctx);
- redisAsyncSetDisconnectCallback (ctx, rspamd_redis_pool_on_disconnect,
- conn);
+ redisAsyncSetDisconnectCallback (ctx, rspamd_redis_pool_on_disconnect);
if (password) {
redisAsyncCommand (ctx, NULL, NULL,
More information about the Commits
mailing list