diff options
| author | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-11-01 09:52:17 +0100 | 
|---|---|---|
| committer | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-11-01 09:52:17 +0100 | 
| commit | 437eea80fce125b800142bd00ab701000f78e57e (patch) | |
| tree | 5102793d6b95cfa4b0f13db9537a320f1169ebf8 | |
| parent | 4e3bd7893d4e59ca23b629cc9084e9c61d5edf25 (diff) | |
| download | hiredict-437eea80fce125b800142bd00ab701000f78e57e.tar.xz | |
Make error ptr accessible from async context
| -rw-r--r-- | async.c | 12 | ||||
| -rw-r--r-- | async.h | 3 | 
2 files changed, 14 insertions, 1 deletions
| @@ -40,9 +40,18 @@ static redisAsyncContext *redisAsyncInitialize(redisContext *c) {      return ac;  } +/* We want the error field to be accessible directly instead of requiring + * an indirection to the redisContext struct. */ +static void __redisAsyncCopyError(redisAsyncContext *ac) { +    redisContext *c = &(ac->c); +    if (c->error != NULL) +        ac->error = c->error; +} +  redisAsyncContext *redisAsyncConnect(const char *ip, int port) {      redisContext *c = redisConnectNonBlock(ip,port);      redisAsyncContext *ac = redisAsyncInitialize(c); +    __redisAsyncCopyError(ac);      return ac;  } @@ -78,7 +87,8 @@ static void __redisAsyncDisconnect(redisAsyncContext *ac) {      if (ac->evCleanup) ac->evCleanup(ac->data);      /* Execute callback with proper status */ -    status = (c->error == NULL) ? REDIS_OK : REDIS_ERR; +    __redisAsyncCopyError(ac); +    status = (ac->error == NULL) ? REDIS_OK : REDIS_ERR;      if (ac->onDisconnect) ac->onDisconnect(ac,status);      /* Cleanup self */ @@ -54,6 +54,9 @@ typedef struct redisAsyncContext {      /* Hold the regular context, so it can be realloc'ed. */      redisContext c; +    /* Hold a reference to the error object so it can be used directly. */ +    char *error; +      /* Called when the library expects to start reading/writing.       * The supplied functions should be idempotent. */      void (*evAddRead)(void *privdata); | 
