]>
git.saurik.com Git - redis.git/blob - deps/hiredis/adapters/ae.h
1 #ifndef __HIREDIS_AE_H__
2 #define __HIREDIS_AE_H__
5 #include "../hiredis.h"
8 typedef struct redisAeEvents
{
9 redisAsyncContext
*context
;
15 static void redisAeReadEvent(aeEventLoop
*el
, int fd
, void *privdata
, int mask
) {
16 ((void)el
); ((void)fd
); ((void)mask
);
18 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
19 redisAsyncHandleRead(e
->context
);
22 static void redisAeWriteEvent(aeEventLoop
*el
, int fd
, void *privdata
, int mask
) {
23 ((void)el
); ((void)fd
); ((void)mask
);
25 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
26 redisAsyncHandleWrite(e
->context
);
29 static void redisAeAddRead(void *privdata
) {
30 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
31 aeEventLoop
*loop
= e
->loop
;
34 aeCreateFileEvent(loop
,e
->fd
,AE_READABLE
,redisAeReadEvent
,e
);
38 static void redisAeDelRead(void *privdata
) {
39 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
40 aeEventLoop
*loop
= e
->loop
;
43 aeDeleteFileEvent(loop
,e
->fd
,AE_READABLE
);
47 static void redisAeAddWrite(void *privdata
) {
48 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
49 aeEventLoop
*loop
= e
->loop
;
52 aeCreateFileEvent(loop
,e
->fd
,AE_WRITABLE
,redisAeWriteEvent
,e
);
56 static void redisAeDelWrite(void *privdata
) {
57 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
58 aeEventLoop
*loop
= e
->loop
;
61 aeDeleteFileEvent(loop
,e
->fd
,AE_WRITABLE
);
65 static void redisAeCleanup(void *privdata
) {
66 redisAeEvents
*e
= (redisAeEvents
*)privdata
;
67 redisAeDelRead(privdata
);
68 redisAeDelWrite(privdata
);
72 static int redisAeAttach(aeEventLoop
*loop
, redisAsyncContext
*ac
) {
73 redisContext
*c
= &(ac
->c
);
76 /* Nothing should be attached when something is already attached */
77 if (ac
->ev
.data
!= NULL
)
80 /* Create container for context and r/w events */
81 e
= (redisAeEvents
*)malloc(sizeof(*e
));
85 e
->reading
= e
->writing
= 0;
87 /* Register functions to start/stop listening for events */
88 ac
->ev
.addRead
= redisAeAddRead
;
89 ac
->ev
.delRead
= redisAeDelRead
;
90 ac
->ev
.addWrite
= redisAeAddWrite
;
91 ac
->ev
.delWrite
= redisAeDelWrite
;
92 ac
->ev
.cleanup
= redisAeCleanup
;