summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-12-01 16:43:21 +0100
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-12-01 16:43:24 +0100
commitaf7369a253247e23f699a0d803f68b3ade022044 (patch)
treeaf3aae5b9667cd9b1008f3cd2d6c4389c561aa5e
parent9af1574d6e65bac7b39e7036056cb326064f1ac4 (diff)
Use extra field for adapter-specific data
This makes sure that the "data" field on the asynchronous context can be used for user-specific data.
-rw-r--r--adapters/ae.h4
-rw-r--r--adapters/libev.h4
-rw-r--r--adapters/libevent.h4
-rw-r--r--async.c13
-rw-r--r--async.h3
5 files changed, 16 insertions, 12 deletions
diff --git a/adapters/ae.h b/adapters/ae.h
index 8d0b526..b8b2228 100644
--- a/adapters/ae.h
+++ b/adapters/ae.h
@@ -72,7 +72,7 @@ int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {
redisAeEvents *e;
/* Nothing should be attached when something is already attached */
- if (ac->data != NULL)
+ if (ac->_adapter_data != NULL)
return REDIS_ERR;
/* Create container for context and r/w events */
@@ -88,7 +88,7 @@ int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {
ac->evAddWrite = redisAeAddWrite;
ac->evDelWrite = redisAeDelWrite;
ac->evCleanup = redisAeCleanup;
- ac->data = e;
+ ac->_adapter_data = e;
return REDIS_OK;
}
diff --git a/adapters/libev.h b/adapters/libev.h
index 8a2a4f3..3b9ed65 100644
--- a/adapters/libev.h
+++ b/adapters/libev.h
@@ -82,7 +82,7 @@ int redisLibevAttach(EV_P_ redisAsyncContext *ac) {
redisLibevEvents *e;
/* Nothing should be attached when something is already attached */
- if (ac->data != NULL)
+ if (ac->_adapter_data != NULL)
return REDIS_ERR;
/* Create container for context and r/w events */
@@ -103,7 +103,7 @@ int redisLibevAttach(EV_P_ redisAsyncContext *ac) {
ac->evAddWrite = redisLibevAddWrite;
ac->evDelWrite = redisLibevDelWrite;
ac->evCleanup = redisLibevCleanup;
- ac->data = e;
+ ac->_adapter_data = e;
/* Initialize read/write events */
ev_io_init(&e->rev,redisLibevReadEvent,c->fd,EV_READ);
diff --git a/adapters/libevent.h b/adapters/libevent.h
index 8531c52..dc1f5c7 100644
--- a/adapters/libevent.h
+++ b/adapters/libevent.h
@@ -52,7 +52,7 @@ int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) {
redisLibeventEvents *e;
/* Nothing should be attached when something is already attached */
- if (ac->data != NULL)
+ if (ac->_adapter_data != NULL)
return REDIS_ERR;
/* Create container for context and r/w events */
@@ -65,7 +65,7 @@ int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) {
ac->evAddWrite = redisLibeventAddWrite;
ac->evDelWrite = redisLibeventDelWrite;
ac->evCleanup = redisLibeventCleanup;
- ac->data = e;
+ ac->_adapter_data = e;
/* Initialize and install read/write events */
event_set(&e->rev,c->fd,EV_READ,redisLibeventReadEvent,e);
diff --git a/async.c b/async.c
index 6821755..1dcb04e 100644
--- a/async.c
+++ b/async.c
@@ -41,6 +41,7 @@ static redisAsyncContext *redisAsyncInitialize(redisContext *c) {
ac->err = 0;
ac->errstr = NULL;
ac->data = NULL;
+ ac->_adapter_data = NULL;
ac->evAddRead = NULL;
ac->evDelRead = NULL;
ac->evAddWrite = NULL;
@@ -162,7 +163,7 @@ static void __redisAsyncDisconnect(redisAsyncContext *ac) {
}
/* Signal event lib to clean up */
- if (ac->evCleanup) ac->evCleanup(ac->data);
+ if (ac->evCleanup) ac->evCleanup(ac->_adapter_data);
/* Execute callback with proper status */
if (ac->onDisconnect) ac->onDisconnect(ac,status);
@@ -215,7 +216,7 @@ void redisAsyncHandleRead(redisAsyncContext *ac) {
__redisAsyncDisconnect(ac);
} else {
/* Always re-schedule reads */
- if (ac->evAddRead) ac->evAddRead(ac->data);
+ if (ac->evAddRead) ac->evAddRead(ac->_adapter_data);
redisProcessCallbacks(ac);
}
}
@@ -229,13 +230,13 @@ void redisAsyncHandleWrite(redisAsyncContext *ac) {
} else {
/* Continue writing when not done, stop writing otherwise */
if (!done) {
- if (ac->evAddWrite) ac->evAddWrite(ac->data);
+ if (ac->evAddWrite) ac->evAddWrite(ac->_adapter_data);
} else {
- if (ac->evDelWrite) ac->evDelWrite(ac->data);
+ if (ac->evDelWrite) ac->evDelWrite(ac->_adapter_data);
}
/* Always schedule reads when something was written */
- if (ac->evAddRead) ac->evAddRead(ac->data);
+ if (ac->evAddRead) ac->evAddRead(ac->_adapter_data);
}
}
@@ -258,7 +259,7 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void
__redisPushCallback(&ac->replies,&cb);
/* Always schedule a write when the write buffer is non-empty */
- if (ac->evAddWrite) ac->evAddWrite(ac->data);
+ if (ac->evAddWrite) ac->evAddWrite(ac->_adapter_data);
return REDIS_OK;
}
diff --git a/async.h b/async.h
index f93fc0d..19c522b 100644
--- a/async.h
+++ b/async.h
@@ -65,6 +65,9 @@ typedef struct redisAsyncContext {
/* Not used by hiredis */
void *data;
+ /* Used by the different event lib adapters to store their private data */
+ void *_adapter_data;
+
/* Called when the library expects to start reading/writing.
* The supplied functions should be idempotent. */
void (*evAddRead)(void *privdata);