]>
git.saurik.com Git - redis.git/blob - deps/hiredis/adapters/ae.h
3 #include "../hiredis.h"
6 typedef struct redisAeEvents
{
7 redisAsyncContext
*context
;
13 void redisAeReadEvent(aeEventLoop
*el
, int fd
, void *privdata
, int mask
) {
14 ((void)el
); ((void)fd
); ((void)mask
);
16 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
17 redisAsyncHandleRead(e
->context
);
20 void redisAeWriteEvent(aeEventLoop
*el
, int fd
, void *privdata
, int mask
) {
21 ((void)el
); ((void)fd
); ((void)mask
);
23 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
24 redisAsyncHandleWrite(e
->context
);
27 void redisAeAddRead(void *privdata
) {
28 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
29 aeEventLoop
*loop
= e
->loop
;
32 aeCreateFileEvent(loop
,e
->fd
,AE_READABLE
,redisAeReadEvent
,e
);
36 void redisAeDelRead(void *privdata
) {
37 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
38 aeEventLoop
*loop
= e
->loop
;
41 aeDeleteFileEvent(loop
,e
->fd
,AE_READABLE
);
45 void redisAeAddWrite(void *privdata
) {
46 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
47 aeEventLoop
*loop
= e
->loop
;
50 aeCreateFileEvent(loop
,e
->fd
,AE_WRITABLE
,redisAeWriteEvent
,e
);
54 void redisAeDelWrite(void *privdata
) {
55 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
56 aeEventLoop
*loop
= e
->loop
;
59 aeDeleteFileEvent(loop
,e
->fd
,AE_WRITABLE
);
63 void redisAeCleanup(void *privdata
) {
64 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
65 redisAeDelRead(privdata
);
66 redisAeDelWrite(privdata
);
70 int redisAeAttach(aeEventLoop
*loop
, redisAsyncContext
*ac
) {
71 redisContext
*c
= &(ac
->c
);
74 /* Nothing should be attached when something is already attached */
75 if (ac
->_adapter_data
!= NULL
)
78 /* Create container for context and r/w events */
79 e
= (redisAeEvents
*)malloc(sizeof(*e
));
83 e
->reading
= e
->writing
= 0;
85 /* Register functions to start/stop listening for events */
86 ac
->evAddRead
= redisAeAddRead
;
87 ac
->evDelRead
= redisAeDelRead
;
88 ac
->evAddWrite
= redisAeAddWrite
;
89 ac
->evDelWrite
= redisAeDelWrite
;
90 ac
->evCleanup
= redisAeCleanup
;
91 ac
->_adapter_data
= e
;