Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
fb49cd19
Commit
fb49cd19
authored
Nov 23, 2010
by
Pieter Noordhuis
Browse files
Make the libev adapter work without support for multiple event loops
parent
808e43e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
adapters/libev.h
View file @
fb49cd19
...
...
@@ -10,47 +10,63 @@ typedef struct redisLibevEvents {
ev_io
rev
,
wev
;
}
redisLibevEvents
;
void
redisLibevReadEvent
(
struct
ev_loop
*
loop
,
ev_io
*
watcher
,
int
revents
)
{
((
void
)
loop
);
((
void
)
revents
);
void
redisLibevReadEvent
(
EV_P_
ev_io
*
watcher
,
int
revents
)
{
#if EV_MULTIPLICITY
((
void
)
loop
);
#endif
((
void
)
revents
);
redisLibevEvents
*
e
=
(
redisLibevEvents
*
)
watcher
->
data
;
redisAsyncHandleRead
(
e
->
context
);
}
void
redisLibevWriteEvent
(
struct
ev_loop
*
loop
,
ev_io
*
watcher
,
int
revents
)
{
((
void
)
loop
);
((
void
)
revents
);
void
redisLibevWriteEvent
(
EV_P_
ev_io
*
watcher
,
int
revents
)
{
#if EV_MULTIPLICITY
((
void
)
loop
);
#endif
((
void
)
revents
);
redisLibevEvents
*
e
=
(
redisLibevEvents
*
)
watcher
->
data
;
redisAsyncHandleWrite
(
e
->
context
);
}
void
redisLibevAddRead
(
void
*
privdata
)
{
redisLibevEvents
*
e
=
(
redisLibevEvents
*
)
privdata
;
struct
ev_loop
*
loop
=
e
->
loop
;
((
void
)
loop
);
if
(
!
e
->
reading
)
{
e
->
reading
=
1
;
ev_io_start
(
e
->
loop
,
&
e
->
rev
);
ev_io_start
(
EV_A_
&
e
->
rev
);
}
}
void
redisLibevDelRead
(
void
*
privdata
)
{
redisLibevEvents
*
e
=
(
redisLibevEvents
*
)
privdata
;
struct
ev_loop
*
loop
=
e
->
loop
;
((
void
)
loop
);
if
(
e
->
reading
)
{
e
->
reading
=
0
;
ev_io_stop
(
e
->
loop
,
&
e
->
rev
);
ev_io_stop
(
EV_A_
&
e
->
rev
);
}
}
void
redisLibevAddWrite
(
void
*
privdata
)
{
redisLibevEvents
*
e
=
(
redisLibevEvents
*
)
privdata
;
struct
ev_loop
*
loop
=
e
->
loop
;
((
void
)
loop
);
if
(
!
e
->
writing
)
{
e
->
writing
=
1
;
ev_io_start
(
e
->
loop
,
&
e
->
wev
);
ev_io_start
(
EV_A_
&
e
->
wev
);
}
}
void
redisLibevDelWrite
(
void
*
privdata
)
{
redisLibevEvents
*
e
=
(
redisLibevEvents
*
)
privdata
;
struct
ev_loop
*
loop
=
e
->
loop
;
((
void
)
loop
);
if
(
e
->
writing
)
{
e
->
writing
=
0
;
ev_io_stop
(
e
->
loop
,
&
e
->
wev
);
ev_io_stop
(
EV_A_
&
e
->
wev
);
}
}
...
...
@@ -61,7 +77,7 @@ void redisLibevCleanup(void *privdata) {
free
(
e
);
}
int
redisLibevAttach
(
redisAsyncContext
*
ac
,
struct
ev_loop
*
loop
)
{
int
redisLibevAttach
(
EV_P_
redisAsyncContext
*
ac
)
{
redisContext
*
c
=
&
(
ac
->
c
);
redisLibevEvents
*
e
;
...
...
@@ -72,7 +88,11 @@ int redisLibevAttach(redisAsyncContext *ac, struct ev_loop *loop) {
/* Create container for context and r/w events */
e
=
(
redisLibevEvents
*
)
malloc
(
sizeof
(
*
e
));
e
->
context
=
ac
;
#if EV_MULTIPLICITY
e
->
loop
=
loop
;
#else
e
->
loop
=
NULL
;
#endif
e
->
reading
=
e
->
writing
=
0
;
e
->
rev
.
data
=
e
;
e
->
wev
.
data
=
e
;
...
...
example-libev.c
View file @
fb49cd19
...
...
@@ -23,7 +23,6 @@ void disconnectCallback(const redisAsyncContext *c, int status) {
int
main
(
int
argc
,
char
**
argv
)
{
signal
(
SIGPIPE
,
SIG_IGN
);
struct
ev_loop
*
loop
=
ev_default_loop
(
0
);
redisAsyncContext
*
c
=
redisAsyncConnect
(
"127.0.0.1"
,
6379
);
if
(
c
->
err
)
{
...
...
@@ -32,10 +31,10 @@ int main (int argc, char **argv) {
return
1
;
}
redisLibevAttach
(
c
,
loop
);
redisLibevAttach
(
EV_DEFAULT_
c
);
redisAsyncSetDisconnectCallback
(
c
,
disconnectCallback
);
redisAsyncCommand
(
c
,
NULL
,
NULL
,
"SET key %b"
,
argv
[
argc
-
1
],
strlen
(
argv
[
argc
-
1
]));
redisAsyncCommand
(
c
,
getCallback
,
(
char
*
)
"end-1"
,
"GET key"
);
ev_loop
(
loop
,
0
);
ev_loop
(
EV_DEFAULT_
0
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment