From fb49cd19887e45e1118b9a3b09f582305c842e4b Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Tue, 23 Nov 2010 15:55:27 +0100 Subject: Make the libev adapter work without support for multiple event loops --- adapters/libev.h | 38 +++++++++++++++++++++++++++++--------- example-libev.c | 5 ++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/adapters/libev.h b/adapters/libev.h index 9e28bc4..8a2a4f3 100644 --- a/adapters/libev.h +++ b/adapters/libev.h @@ -10,47 +10,63 @@ typedef struct redisLibevEvents { ev_io rev, wev; } redisLibevEvents; -void redisLibevReadEvent(struct ev_loop *loop, ev_io *watcher, int revents) { - ((void)loop); ((void)revents); +void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) { +#if EV_MULTIPLICITY + ((void)loop); +#endif + ((void)revents); + redisLibevEvents *e = (redisLibevEvents*)watcher->data; redisAsyncHandleRead(e->context); } -void redisLibevWriteEvent(struct ev_loop *loop, ev_io *watcher, int revents) { - ((void)loop); ((void)revents); +void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) { +#if EV_MULTIPLICITY + ((void)loop); +#endif + ((void)revents); + redisLibevEvents *e = (redisLibevEvents*)watcher->data; redisAsyncHandleWrite(e->context); } void redisLibevAddRead(void *privdata) { redisLibevEvents *e = (redisLibevEvents*)privdata; + struct ev_loop *loop = e->loop; + ((void)loop); if (!e->reading) { e->reading = 1; - ev_io_start(e->loop,&e->rev); + ev_io_start(EV_A_ &e->rev); } } void redisLibevDelRead(void *privdata) { redisLibevEvents *e = (redisLibevEvents*)privdata; + struct ev_loop *loop = e->loop; + ((void)loop); if (e->reading) { e->reading = 0; - ev_io_stop(e->loop,&e->rev); + ev_io_stop(EV_A_ &e->rev); } } void redisLibevAddWrite(void *privdata) { redisLibevEvents *e = (redisLibevEvents*)privdata; + struct ev_loop *loop = e->loop; + ((void)loop); if (!e->writing) { e->writing = 1; - ev_io_start(e->loop,&e->wev); + ev_io_start(EV_A_ &e->wev); } } void redisLibevDelWrite(void *privdata) { redisLibevEvents *e = (redisLibevEvents*)privdata; + struct ev_loop *loop = e->loop; + ((void)loop); if (e->writing) { e->writing = 0; - ev_io_stop(e->loop,&e->wev); + ev_io_stop(EV_A_ &e->wev); } } @@ -61,7 +77,7 @@ void redisLibevCleanup(void *privdata) { free(e); } -int redisLibevAttach(redisAsyncContext *ac, struct ev_loop *loop) { +int redisLibevAttach(EV_P_ redisAsyncContext *ac) { redisContext *c = &(ac->c); redisLibevEvents *e; @@ -72,7 +88,11 @@ int redisLibevAttach(redisAsyncContext *ac, struct ev_loop *loop) { /* Create container for context and r/w events */ e = (redisLibevEvents*)malloc(sizeof(*e)); e->context = ac; +#if EV_MULTIPLICITY e->loop = loop; +#else + e->loop = NULL; +#endif e->reading = e->writing = 0; e->rev.data = e; e->wev.data = e; diff --git a/example-libev.c b/example-libev.c index 199d706..ecf8c02 100644 --- a/example-libev.c +++ b/example-libev.c @@ -23,7 +23,6 @@ void disconnectCallback(const redisAsyncContext *c, int status) { int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); - struct ev_loop *loop = ev_default_loop(0); redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); if (c->err) { @@ -32,10 +31,10 @@ int main (int argc, char **argv) { return 1; } - redisLibevAttach(c,loop); + redisLibevAttach(EV_DEFAULT_ c); redisAsyncSetDisconnectCallback(c,disconnectCallback); redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); - ev_loop(loop, 0); + ev_loop(EV_DEFAULT_ 0); return 0; } -- cgit v1.2.3