forked from redis/redis
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
678 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <sys/types.h> | ||
#include <ae.h> | ||
#include "../hiredis.h" | ||
#include "../async.h" | ||
|
||
typedef struct redisAeEvents { | ||
redisAsyncContext *context; | ||
aeEventLoop *loop; | ||
int fd; | ||
int reading, writing; | ||
} redisAeEvents; | ||
|
||
void redisAeReadEvent(aeEventLoop *el, int fd, void *privdata, int mask) { | ||
((void)el); ((void)fd); ((void)mask); | ||
|
||
redisAeEvents *e = (redisAeEvents*)privdata; | ||
redisAsyncHandleRead(e->context); | ||
} | ||
|
||
void redisAeWriteEvent(aeEventLoop *el, int fd, void *privdata, int mask) { | ||
((void)el); ((void)fd); ((void)mask); | ||
|
||
redisAeEvents *e = (redisAeEvents*)privdata; | ||
redisAsyncHandleWrite(e->context); | ||
} | ||
|
||
void redisAeAddRead(void *privdata) { | ||
redisAeEvents *e = (redisAeEvents*)privdata; | ||
aeEventLoop *loop = e->loop; | ||
if (!e->reading) { | ||
e->reading = 1; | ||
aeCreateFileEvent(loop,e->fd,AE_READABLE,redisAeReadEvent,e); | ||
} | ||
} | ||
|
||
void redisAeDelRead(void *privdata) { | ||
redisAeEvents *e = (redisAeEvents*)privdata; | ||
aeEventLoop *loop = e->loop; | ||
if (e->reading) { | ||
e->reading = 0; | ||
aeDeleteFileEvent(loop,e->fd,AE_READABLE); | ||
} | ||
} | ||
|
||
void redisAeAddWrite(void *privdata) { | ||
redisAeEvents *e = (redisAeEvents*)privdata; | ||
aeEventLoop *loop = e->loop; | ||
if (!e->writing) { | ||
e->writing = 1; | ||
aeCreateFileEvent(loop,e->fd,AE_WRITABLE,redisAeWriteEvent,e); | ||
} | ||
} | ||
|
||
void redisAeDelWrite(void *privdata) { | ||
redisAeEvents *e = (redisAeEvents*)privdata; | ||
aeEventLoop *loop = e->loop; | ||
if (e->writing) { | ||
e->writing = 0; | ||
aeDeleteFileEvent(loop,e->fd,AE_WRITABLE); | ||
} | ||
} | ||
|
||
void redisAeCleanup(void *privdata) { | ||
redisAeEvents *e = (redisAeEvents*)privdata; | ||
redisAeDelRead(privdata); | ||
redisAeDelWrite(privdata); | ||
free(e); | ||
} | ||
|
||
int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) { | ||
redisContext *c = &(ac->c); | ||
redisAeEvents *e; | ||
|
||
/* Nothing should be attached when something is already attached */ | ||
if (ac->_adapter_data != NULL) | ||
return REDIS_ERR; | ||
|
||
/* Create container for context and r/w events */ | ||
e = (redisAeEvents*)malloc(sizeof(*e)); | ||
e->context = ac; | ||
e->loop = loop; | ||
e->fd = c->fd; | ||
e->reading = e->writing = 0; | ||
|
||
/* Register functions to start/stop listening for events */ | ||
ac->evAddRead = redisAeAddRead; | ||
ac->evDelRead = redisAeDelRead; | ||
ac->evAddWrite = redisAeAddWrite; | ||
ac->evDelWrite = redisAeDelWrite; | ||
ac->evCleanup = redisAeCleanup; | ||
ac->_adapter_data = e; | ||
|
||
return REDIS_OK; | ||
} | ||
|
Oops, something went wrong.