]>
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(struct ev_loop
*loop
, ev_io
*watcher
, int revents
) {
14 ((void)loop
); ((void)revents
);
15 redisLibevEvents
*e
= watcher
->data
;
16 redisAsyncHandleRead(e
->context
);
19 void redisLibevWriteEvent(struct ev_loop
*loop
, ev_io
*watcher
, int revents
) {
20 ((void)loop
); ((void)revents
);
21 redisLibevEvents
*e
= watcher
->data
;
22 redisAsyncHandleWrite(e
->context
);
25 void redisLibevAddRead(void *privdata
) {
26 redisLibevEvents
*e
= privdata
;
29 ev_io_start(e
->loop
,&e
->rev
);
33 void redisLibevDelRead(void *privdata
) {
34 redisLibevEvents
*e
= privdata
;
37 ev_io_stop(e
->loop
,&e
->rev
);
41 void redisLibevAddWrite(void *privdata
) {
42 redisLibevEvents
*e
= privdata
;
45 ev_io_start(e
->loop
,&e
->wev
);
49 void redisLibevDelWrite(void *privdata
) {
50 redisLibevEvents
*e
= privdata
;
53 ev_io_stop(e
->loop
,&e
->wev
);
57 void redisLibevCleanup(void *privdata
) {
58 redisLibevEvents
*e
= privdata
;
59 redisLibevDelRead(privdata
);
60 redisLibevDelWrite(privdata
);
64 int redisLibevAttach(redisAsyncContext
*ac
, struct ev_loop
*loop
) {
65 redisContext
*c
= &(ac
->c
);
68 /* Nothing should be attached when something is already attached */
72 /* Create container for context and r/w events */
73 e
= malloc(sizeof(*e
));
76 e
->reading
= e
->writing
= 0;
80 /* Register functions to start/stop listening for events */
81 ac
->evAddRead
= redisLibevAddRead
;
82 ac
->evDelRead
= redisLibevDelRead
;
83 ac
->evAddWrite
= redisLibevAddWrite
;
84 ac
->evDelWrite
= redisLibevDelWrite
;
85 ac
->evCleanup
= redisLibevCleanup
;
88 /* Initialize read/write events */
89 ev_io_init(&e
->rev
,redisLibevReadEvent
,c
->fd
,EV_READ
);
90 ev_io_init(&e
->wev
,redisLibevWriteEvent
,c
->fd
,EV_WRITE
);