From a7acd97ad1fd7c152f7620c0224fba624f226796 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 11 Oct 2010 18:26:38 +0200 Subject: Move event_base code out of libevent.h This removes the need to wrap an event_base pointer in the redisContext struct and allows multiple connections to be used in a single event_base. Also, use the *privdata argument to the provided callbacks to curry the redisEvent struct around. --- extra/hiredis/libevent.h | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'extra/hiredis') diff --git a/extra/hiredis/libevent.h b/extra/hiredis/libevent.h index e4bc6f9..4473d59 100644 --- a/extra/hiredis/libevent.h +++ b/extra/hiredis/libevent.h @@ -11,7 +11,6 @@ typedef struct redisEvents { redisContext *context; redisErrorCallback *err; struct event rev, wev; - struct event_base *base; } redisEvents; void redisLibEventRead(int fd, short event, void *arg) { @@ -74,15 +73,7 @@ void redisLibEventOnFree(redisContext *c, void *privdata) { free(e); } -/* Dispatch libevent loop. */ -int redisLibEventDispatch(redisContext *c) { - if (!c->events) { - return -1; - } - return event_base_dispatch(c->events->base); -} - -redisContext *redisLibEventConnect(const char *ip, int port, redisErrorCallback *err) { +redisContext *redisLibEventConnect(const char *ip, int port, redisErrorCallback *err, struct event_base *base) { redisEvents *e; redisContext *c = redisConnectNonBlock(ip, port, NULL); if (c->error != NULL) { @@ -94,16 +85,14 @@ redisContext *redisLibEventConnect(const char *ip, int port, redisErrorCallback e = malloc(sizeof(*e)); e->context = c; e->err = err; - e->base = event_base_new(); - c->events = e; /* Register callbacks and events */ redisSetDisconnectCallback(e->context, redisLibEventOnDisconnect, e); redisSetCommandCallback(e->context, redisLibEventOnWrite, e); redisSetFreeCallback(e->context, redisLibEventOnFree, e); event_set(&e->rev, e->context->fd, EV_READ, redisLibEventRead, e); - event_base_set(e->base, &e->rev); event_set(&e->wev, e->context->fd, EV_WRITE, redisLibEventWrite, e); - event_base_set(e->base, &e->wev); + event_base_set(base, &e->rev); + event_base_set(base, &e->wev); return c; } -- cgit v1.2.3