]>
git.saurik.com Git - redis.git/blob - deps/hiredis/adapters/libev.h
3 #include "../hiredis.h"
6 typedef struct redisLibevEvents
{
7 redisAsyncContext
*context
;
13 void redisLibevReadEvent(EV_P_ ev_io
*watcher
, int revents
) {
19 redisLibevEvents
*e
= (redisLibevEvents
*)watcher
->data
;
20 redisAsyncHandleRead(e
->context
);
23 void redisLibevWriteEvent(EV_P_ ev_io
*watcher
, int revents
) {
29 redisLibevEvents
*e
= (redisLibevEvents
*)watcher
->data
;
30 redisAsyncHandleWrite(e
->context
);
33 void redisLibevAddRead(void *privdata
) {
34 redisLibevEvents
*e
= (redisLibevEvents
*)privdata
;
35 struct ev_loop
*loop
= e
->loop
;
39 ev_io_start(EV_A_
&e
->rev
);
43 void redisLibevDelRead(void *privdata
) {
44 redisLibevEvents
*e
= (redisLibevEvents
*)privdata
;
45 struct ev_loop
*loop
= e
->loop
;
49 ev_io_stop(EV_A_
&e
->rev
);
53 void redisLibevAddWrite(void *privdata
) {
54 redisLibevEvents
*e
= (redisLibevEvents
*)privdata
;
55 struct ev_loop
*loop
= e
->loop
;
59 ev_io_start(EV_A_
&e
->wev
);
63 void redisLibevDelWrite(void *privdata
) {
64 redisLibevEvents
*e
= (redisLibevEvents
*)privdata
;
65 struct ev_loop
*loop
= e
->loop
;
69 ev_io_stop(EV_A_
&e
->wev
);
73 void redisLibevCleanup(void *privdata
) {
74 redisLibevEvents
*e
= (redisLibevEvents
*)privdata
;
75 redisLibevDelRead(privdata
);
76 redisLibevDelWrite(privdata
);
80 int redisLibevAttach(EV_P_ redisAsyncContext
*ac
) {
81 redisContext
*c
= &(ac
->c
);
84 /* Nothing should be attached when something is already attached */
85 if (ac
->_adapter_data
!= NULL
)
88 /* Create container for context and r/w events */
89 e
= (redisLibevEvents
*)malloc(sizeof(*e
));
96 e
->reading
= e
->writing
= 0;
100 /* Register functions to start/stop listening for events */
101 ac
->evAddRead
= redisLibevAddRead
;
102 ac
->evDelRead
= redisLibevDelRead
;
103 ac
->evAddWrite
= redisLibevAddWrite
;
104 ac
->evDelWrite
= redisLibevDelWrite
;
105 ac
->evCleanup
= redisLibevCleanup
;
106 ac
->_adapter_data
= e
;
108 /* Initialize read/write events */
109 ev_io_init(&e
->rev
,redisLibevReadEvent
,c
->fd
,EV_READ
);
110 ev_io_init(&e
->wev
,redisLibevWriteEvent
,c
->fd
,EV_WRITE
);