]>
git.saurik.com Git - redis.git/blob - deps/hiredis/adapters/libevent.h
1b759c13190ed3a4541cba6092a42f57b7e963c7
3 #include "../hiredis.h"
6 typedef struct redisLibeventEvents
{
7 redisAsyncContext
*context
;
11 void redisLibeventReadEvent(int fd
, short event
, void *arg
) {
12 ((void)fd
); ((void)event
);
13 redisLibeventEvents
*e
= arg
;
14 redisAsyncHandleRead(e
->context
);
17 void redisLibeventWriteEvent(int fd
, short event
, void *arg
) {
18 ((void)fd
); ((void)event
);
19 redisLibeventEvents
*e
= arg
;
20 redisAsyncHandleWrite(e
->context
);
23 void redisLibeventAddRead(void *privdata
) {
24 redisLibeventEvents
*e
= privdata
;
25 event_add(&e
->rev
,NULL
);
28 void redisLibeventDelRead(void *privdata
) {
29 redisLibeventEvents
*e
= privdata
;
33 void redisLibeventAddWrite(void *privdata
) {
34 redisLibeventEvents
*e
= privdata
;
35 event_add(&e
->wev
,NULL
);
38 void redisLibeventDelWrite(void *privdata
) {
39 redisLibeventEvents
*e
= privdata
;
43 void redisLibeventCleanup(void *privdata
) {
44 redisLibeventEvents
*e
= privdata
;
50 int redisLibeventAttach(redisAsyncContext
*ac
, struct event_base
*base
) {
51 redisContext
*c
= &(ac
->c
);
52 redisLibeventEvents
*e
;
54 /* Nothing should be attached when something is already attached */
58 /* Create container for context and r/w events */
59 e
= malloc(sizeof(*e
));
62 /* Register functions to start/stop listening for events */
63 ac
->evAddRead
= redisLibeventAddRead
;
64 ac
->evDelRead
= redisLibeventDelRead
;
65 ac
->evAddWrite
= redisLibeventAddWrite
;
66 ac
->evDelWrite
= redisLibeventDelWrite
;
67 ac
->evCleanup
= redisLibeventCleanup
;
70 /* Initialize and install read/write events */
71 event_set(&e
->rev
,c
->fd
,EV_READ
,redisLibeventReadEvent
,e
);
72 event_set(&e
->wev
,c
->fd
,EV_WRITE
,redisLibeventWriteEvent
,e
);
73 event_base_set(base
,&e
->rev
);
74 event_base_set(base
,&e
->wev
);