diff options
author | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-12-31 11:27:32 +0100 |
---|---|---|
committer | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-12-31 15:49:21 +0100 |
commit | 3ce8d5b08b5d13f550983048ee89293e9f6897ca (patch) | |
tree | 71ff7a5837d05ddb4434e66fbac138332ea61987 | |
parent | 2d53a6a7110b6d28226f653d9f4c94082205017a (diff) | |
download | hiredict-3ce8d5b08b5d13f550983048ee89293e9f6897ca.tar.xz |
Change reply processing code to prepare for pub/sub
-rw-r--r-- | async.c | 16 | ||||
-rw-r--r-- | hiredis.h | 3 |
2 files changed, 17 insertions, 2 deletions
@@ -247,12 +247,20 @@ void redisProcessCallbacks(redisAsyncContext *ac) { break; } - /* Shift callback and execute it */ - assert(__redisShiftCallback(&ac->replies,&cb) == REDIS_OK); + /* Even if the context is subscribed, pending regular callbacks will + * get a reply before pub/sub messages arrive. */ + if (__redisShiftCallback(&ac->replies,&cb) != REDIS_OK) { + /* No more regular callbacks, the context *must* be subscribed. */ + assert(c->flags & REDIS_SUBSCRIBED); + + /* TODO: find the right callback for pub/sub message. */ + } + if (cb.fn != NULL) { c->flags |= REDIS_IN_CALLBACK; cb.fn(ac,reply,cb.privdata); c->flags &= ~REDIS_IN_CALLBACK; + c->fn->freeObject(reply); /* Proceed with free'ing when redisAsyncFree() was called. */ if (c->flags & REDIS_FREEING) { @@ -260,6 +268,10 @@ void redisProcessCallbacks(redisAsyncContext *ac) { return; } } else { + /* No callback for this reply. This can either be a NULL callback, + * or there were no callbacks to begin with. Either way, don't + * abort with an error, but simply ignore it because the client + * doesn't know what the server will spit out over the wire. */ c->fn->freeObject(reply); } } @@ -71,6 +71,9 @@ /* Flag that is set when an async callback is executed. */ #define REDIS_IN_CALLBACK 0x10 +/* Flag that is set when the async context has one or more subscriptions. */ +#define REDIS_SUBSCRIBED 0x20 + #define REDIS_REPLY_STRING 1 #define REDIS_REPLY_ARRAY 2 #define REDIS_REPLY_INTEGER 3 |