Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
206868de
Commit
206868de
authored
Oct 19, 2010
by
Pieter Noordhuis
Browse files
Make error callback argument const
parent
ba42ab2e
Changes
2
Hide whitespace changes
Inline
Side-by-side
extra/hiredis/libevent.h
View file @
206868de
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include <hiredis.h>
#include <hiredis.h>
/* Prototype for the error callback. */
/* Prototype for the error callback. */
typedef
void
(
redisErrorCallback
)(
redisContext
*
);
typedef
void
(
redisErrorCallback
)(
const
redisContext
*
);
/* This struct enables us to pass both the events and the
/* This struct enables us to pass both the events and the
* redisContext to the read and write handlers. */
* redisContext to the read and write handlers. */
...
@@ -73,11 +73,12 @@ void redisLibEventOnFree(redisContext *c, void *privdata) {
...
@@ -73,11 +73,12 @@ void redisLibEventOnFree(redisContext *c, void *privdata) {
free
(
e
);
free
(
e
);
}
}
redisContext
*
redisLibEventConnect
(
const
char
*
ip
,
int
port
,
redisErrorCallback
*
err
,
struct
event_base
*
base
)
{
redisContext
*
redisLibEventConnect
(
struct
event_base
*
base
,
redisErrorCallback
*
err
,
const
char
*
ip
,
int
port
)
{
redisEvents
*
e
;
redisEvents
*
e
;
redisContext
*
c
=
redisConnectNonBlock
(
ip
,
port
,
NULL
);
redisContext
*
c
=
redisConnectNonBlock
(
ip
,
port
,
NULL
);
if
(
c
->
error
!=
NULL
)
{
if
(
c
->
error
!=
NULL
)
{
err
(
c
);
err
(
c
);
redisFree
(
c
);
return
NULL
;
return
NULL
;
}
}
...
...
libevent-example.c
View file @
206868de
...
@@ -11,18 +11,15 @@ void getCallback(redisContext *c, redisReply *reply, const void *privdata) {
...
@@ -11,18 +11,15 @@ void getCallback(redisContext *c, redisReply *reply, const void *privdata) {
redisDisconnect
(
c
);
redisDisconnect
(
c
);
}
}
void
errorCallback
(
redisContext
*
c
)
{
void
errorCallback
(
const
redisContext
*
c
)
{
printf
(
"Error: %s
\n
"
,
c
->
error
);
printf
(
"Error: %s
\n
"
,
c
->
error
);
/* Clean up the context when there was an error */
redisFree
(
c
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
signal
(
SIGPIPE
,
SIG_IGN
);
signal
(
SIGPIPE
,
SIG_IGN
);
struct
event_base
*
base
=
event_base_new
();
struct
event_base
*
base
=
event_base_new
();
redisContext
*
c
=
redisLibEventConnect
(
"127.0.0.1"
,
6379
,
errorCallback
,
base
);
redisContext
*
c
=
redisLibEventConnect
(
base
,
errorCallback
,
"127.0.0.1"
,
6379
);
if
(
c
==
NULL
)
return
1
;
if
(
c
==
NULL
)
return
1
;
redisCommand
(
c
,
"SET key %b"
,
argv
[
argc
-
1
],
strlen
(
argv
[
argc
-
1
]));
redisCommand
(
c
,
"SET key %b"
,
argv
[
argc
-
1
],
strlen
(
argv
[
argc
-
1
]));
...
...
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