summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorNicolas Favre-Felix <n.favrefelix@gmail.com>2010-10-10 20:51:27 +0200
committerNicolas Favre-Felix <n.favrefelix@gmail.com>2010-10-10 20:51:27 +0200
commit135e9265acfb4f89b7fff73e985b370c6169ef23 (patch)
treedb97e66073f41811f793b9c9541790e1260c299c /extra
parent96510ce86ade991a7dc968587c3c618cc9bf5a88 (diff)
Added event_base to libevent code.
Diffstat (limited to 'extra')
-rw-r--r--extra/hiredis/libevent.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/extra/hiredis/libevent.h b/extra/hiredis/libevent.h
index c9bf4f1..e4bc6f9 100644
--- a/extra/hiredis/libevent.h
+++ b/extra/hiredis/libevent.h
@@ -1,3 +1,4 @@
+typedef unsigned char u_char; /* libevents needs u_char */
#include <event.h>
#include <hiredis.h>
@@ -10,6 +11,7 @@ typedef struct redisEvents {
redisContext *context;
redisErrorCallback *err;
struct event rev, wev;
+ struct event_base *base;
} redisEvents;
void redisLibEventRead(int fd, short event, void *arg) {
@@ -72,6 +74,14 @@ 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) {
redisEvents *e;
redisContext *c = redisConnectNonBlock(ip, port, NULL);
@@ -84,12 +94,16 @@ 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);
- return e->context;
+ event_base_set(e->base, &e->wev);
+ return c;
}