Commit 026d5ae7 authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Use macro's for event loop hooks

parent 3cc6a7f2
...@@ -38,6 +38,22 @@ ...@@ -38,6 +38,22 @@
#include "dict.c" #include "dict.c"
#include "sds.h" #include "sds.h"
#define _EL_ADD_READ(ctx) do { \
if ((ctx)->ev.addRead) (ctx)->ev.addRead((ctx)->ev.data); \
} while(0)
#define _EL_DEL_READ(ctx) do { \
if ((ctx)->ev.delRead) (ctx)->ev.delRead((ctx)->ev.data); \
} while(0)
#define _EL_ADD_WRITE(ctx) do { \
if ((ctx)->ev.addWrite) (ctx)->ev.addWrite((ctx)->ev.data); \
} while(0)
#define _EL_DEL_WRITE(ctx) do { \
if ((ctx)->ev.delWrite) (ctx)->ev.delWrite((ctx)->ev.data); \
} while(0)
#define _EL_CLEANUP(ctx) do { \
if ((ctx)->ev.cleanup) (ctx)->ev.cleanup((ctx)->ev.data); \
} while(0);
/* Forward declaration of function in hiredis.c */ /* Forward declaration of function in hiredis.c */
void __redisAppendCommand(redisContext *c, char *cmd, size_t len); void __redisAppendCommand(redisContext *c, char *cmd, size_t len);
...@@ -143,7 +159,7 @@ int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn ...@@ -143,7 +159,7 @@ int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn
/* The common way to detect an established connection is to wait for /* The common way to detect an established connection is to wait for
* the first write event to be fired. This assumes the related event * the first write event to be fired. This assumes the related event
* library functions are already set. */ * library functions are already set. */
if (ac->ev.addWrite) ac->ev.addWrite(ac->ev.data); _EL_ADD_WRITE(ac);
return REDIS_OK; return REDIS_OK;
} }
return REDIS_ERR; return REDIS_ERR;
...@@ -231,7 +247,7 @@ static void __redisAsyncFree(redisAsyncContext *ac) { ...@@ -231,7 +247,7 @@ static void __redisAsyncFree(redisAsyncContext *ac) {
dictRelease(ac->sub.patterns); dictRelease(ac->sub.patterns);
/* Signal event lib to clean up */ /* Signal event lib to clean up */
if (ac->ev.cleanup) ac->ev.cleanup(ac->ev.data); _EL_CLEANUP(ac);
/* Execute disconnect callback. When redisAsyncFree() initiated destroying /* Execute disconnect callback. When redisAsyncFree() initiated destroying
* this context, the status will always be REDIS_OK. */ * this context, the status will always be REDIS_OK. */
...@@ -413,7 +429,7 @@ void redisAsyncHandleRead(redisAsyncContext *ac) { ...@@ -413,7 +429,7 @@ void redisAsyncHandleRead(redisAsyncContext *ac) {
__redisAsyncDisconnect(ac); __redisAsyncDisconnect(ac);
} else { } else {
/* Always re-schedule reads */ /* Always re-schedule reads */
if (ac->ev.addRead) ac->ev.addRead(ac->ev.data); _EL_ADD_READ(ac);
redisProcessCallbacks(ac); redisProcessCallbacks(ac);
} }
} }
...@@ -426,14 +442,13 @@ void redisAsyncHandleWrite(redisAsyncContext *ac) { ...@@ -426,14 +442,13 @@ void redisAsyncHandleWrite(redisAsyncContext *ac) {
__redisAsyncDisconnect(ac); __redisAsyncDisconnect(ac);
} else { } else {
/* Continue writing when not done, stop writing otherwise */ /* Continue writing when not done, stop writing otherwise */
if (!done) { if (!done)
if (ac->ev.addWrite) ac->ev.addWrite(ac->ev.data); _EL_ADD_WRITE(ac);
} else { else
if (ac->ev.delWrite) ac->ev.delWrite(ac->ev.data); _EL_DEL_WRITE(ac);
}
/* Always schedule reads after writes */ /* Always schedule reads after writes */
if (ac->ev.addRead) ac->ev.addRead(ac->ev.data); _EL_ADD_READ(ac);
/* Fire onConnect when this is the first write event. */ /* Fire onConnect when this is the first write event. */
if (!(c->flags & REDIS_CONNECTED)) { if (!(c->flags & REDIS_CONNECTED)) {
...@@ -517,7 +532,7 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void ...@@ -517,7 +532,7 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void
__redisAppendCommand(c,cmd,len); __redisAppendCommand(c,cmd,len);
/* Always schedule a write when the write buffer is non-empty */ /* Always schedule a write when the write buffer is non-empty */
if (ac->ev.addWrite) ac->ev.addWrite(ac->ev.data); _EL_ADD_WRITE(ac);
return REDIS_OK; return REDIS_OK;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment