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
ba42ab2e
Commit
ba42ab2e
authored
Oct 19, 2010
by
Pieter Noordhuis
Browse files
Revert privdata in context callbacks to being non-const
parent
f9596db9
Changes
3
Show whitespace changes
Inline
Side-by-side
hiredis.c
View file @
ba42ab2e
...
@@ -631,20 +631,20 @@ redisContext *redisConnectNonBlock(const char *ip, int port, redisReplyFunctions
...
@@ -631,20 +631,20 @@ redisContext *redisConnectNonBlock(const char *ip, int port, redisReplyFunctions
}
}
/* Register callback that is triggered when redisDisconnect is called. */
/* Register callback that is triggered when redisDisconnect is called. */
void
redisSetDisconnectCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
const
void
*
privdata
)
{
void
redisSetDisconnectCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
void
*
privdata
)
{
c
->
cbDisconnect
.
fn
=
fn
;
c
->
cbDisconnect
.
fn
=
fn
;
c
->
cbDisconnect
.
privdata
=
privdata
;
c
->
cbDisconnect
.
privdata
=
privdata
;
}
}
/* Register callback that is triggered when a command is put in the output
/* Register callback that is triggered when a command is put in the output
* buffer when the context is non-blocking. */
* buffer when the context is non-blocking. */
void
redisSetCommandCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
const
void
*
privdata
)
{
void
redisSetCommandCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
void
*
privdata
)
{
c
->
cbCommand
.
fn
=
fn
;
c
->
cbCommand
.
fn
=
fn
;
c
->
cbCommand
.
privdata
=
privdata
;
c
->
cbCommand
.
privdata
=
privdata
;
}
}
/* Register callback that is triggered when the context is free'd. */
/* Register callback that is triggered when the context is free'd. */
void
redisSetFreeCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
const
void
*
privdata
)
{
void
redisSetFreeCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
void
*
privdata
)
{
c
->
cbFree
.
fn
=
fn
;
c
->
cbFree
.
fn
=
fn
;
c
->
cbFree
.
privdata
=
privdata
;
c
->
cbFree
.
privdata
=
privdata
;
}
}
...
...
hiredis.h
View file @
ba42ab2e
...
@@ -77,7 +77,7 @@ typedef struct redisReplyObjectFunctions {
...
@@ -77,7 +77,7 @@ typedef struct redisReplyObjectFunctions {
struct
redisContext
;
/* need forward declaration of redisContext */
struct
redisContext
;
/* need forward declaration of redisContext */
/* Callbacks triggered on non-reply events. */
/* Callbacks triggered on non-reply events. */
typedef
void
(
redisContextCallbackFn
)(
struct
redisContext
*
,
const
void
*
);
typedef
void
(
redisContextCallbackFn
)(
struct
redisContext
*
,
void
*
);
/* Reply callback prototype and container */
/* Reply callback prototype and container */
typedef
void
(
redisCallbackFn
)(
struct
redisContext
*
,
redisReply
*
,
const
void
*
);
typedef
void
(
redisCallbackFn
)(
struct
redisContext
*
,
redisReply
*
,
const
void
*
);
...
@@ -85,7 +85,7 @@ typedef void (redisCallbackFn)(struct redisContext*, redisReply*, const void*);
...
@@ -85,7 +85,7 @@ typedef void (redisCallbackFn)(struct redisContext*, redisReply*, const void*);
/* Callback containers */
/* Callback containers */
typedef
struct
redisContextCallback
{
typedef
struct
redisContextCallback
{
redisContextCallbackFn
*
fn
;
redisContextCallbackFn
*
fn
;
const
void
*
privdata
;
void
*
privdata
;
}
redisContextCallback
;
}
redisContextCallback
;
typedef
struct
redisCallback
{
typedef
struct
redisCallback
{
...
@@ -135,16 +135,16 @@ int redisProcessCallbacks(redisContext *c);
...
@@ -135,16 +135,16 @@ int redisProcessCallbacks(redisContext *c);
/* The disconnect callback is called *immediately* when redisDisconnect()
/* The disconnect callback is called *immediately* when redisDisconnect()
* is called. It is called only once for every redisContext (since hiredis
* is called. It is called only once for every redisContext (since hiredis
* currently does not support reconnecting an existing context). */
* currently does not support reconnecting an existing context). */
void
redisSetDisconnectCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
const
void
*
privdata
);
void
redisSetDisconnectCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
void
*
privdata
);
/* The command callback is called every time redisCommand() is called in a
/* The command callback is called every time redisCommand() is called in a
* non-blocking context. It is called *after* the formatted command has been
* non-blocking context. It is called *after* the formatted command has been
* appended to the write buffer. */
* appended to the write buffer. */
void
redisSetCommandCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
const
void
*
privdata
);
void
redisSetCommandCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
void
*
privdata
);
/* The free callback is called *before* all allocations are free'd. Use it to
/* The free callback is called *before* all allocations are free'd. Use it to
* release resources that depend/use the redisContext that is being free'd. */
* release resources that depend/use the redisContext that is being free'd. */
void
redisSetFreeCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
const
void
*
privdata
);
void
redisSetFreeCallback
(
redisContext
*
c
,
redisContextCallbackFn
*
fn
,
void
*
privdata
);
/* Issue a command to Redis. In a blocking context, it returns the reply. When
/* Issue a command to Redis. In a blocking context, it returns the reply. When
* an error occurs, it returns NULL and you should read redisContext->error
* an error occurs, it returns NULL and you should read redisContext->error
...
...
test.c
View file @
ba42ab2e
...
@@ -195,7 +195,7 @@ static void cleanup() {
...
@@ -195,7 +195,7 @@ static void cleanup() {
}
}
static
long
__test_callback_flags
=
0
;
static
long
__test_callback_flags
=
0
;
static
void
__test_callback
(
redisContext
*
c
,
const
void
*
privdata
)
{
static
void
__test_callback
(
redisContext
*
c
,
void
*
privdata
)
{
((
void
)
c
);
((
void
)
c
);
/* Shift to detect execution order */
/* Shift to detect execution order */
__test_callback_flags
<<=
8
;
__test_callback_flags
<<=
8
;
...
@@ -218,7 +218,7 @@ static void test_nonblocking_connection() {
...
@@ -218,7 +218,7 @@ static void test_nonblocking_connection() {
__test_callback_flags
=
0
;
__test_callback_flags
=
0
;
test
(
"Calls command callback when command is issued: "
);
test
(
"Calls command callback when command is issued: "
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
redisSetCommandCallback
(
c
,
__test_callback
,(
const
void
*
)
1
);
redisSetCommandCallback
(
c
,
__test_callback
,(
void
*
)
1
);
redisCommand
(
c
,
"PING"
);
redisCommand
(
c
,
"PING"
);
test_cond
(
__test_callback_flags
==
1
);
test_cond
(
__test_callback_flags
==
1
);
redisFree
(
c
);
redisFree
(
c
);
...
@@ -226,7 +226,7 @@ static void test_nonblocking_connection() {
...
@@ -226,7 +226,7 @@ static void test_nonblocking_connection() {
__test_callback_flags
=
0
;
__test_callback_flags
=
0
;
test
(
"Calls disconnect callback on redisDisconnect: "
);
test
(
"Calls disconnect callback on redisDisconnect: "
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
redisSetDisconnectCallback
(
c
,
__test_callback
,(
const
void
*
)
2
);
redisSetDisconnectCallback
(
c
,
__test_callback
,(
void
*
)
2
);
redisDisconnect
(
c
);
redisDisconnect
(
c
);
test_cond
(
__test_callback_flags
==
2
);
test_cond
(
__test_callback_flags
==
2
);
redisFree
(
c
);
redisFree
(
c
);
...
@@ -234,8 +234,8 @@ static void test_nonblocking_connection() {
...
@@ -234,8 +234,8 @@ static void test_nonblocking_connection() {
__test_callback_flags
=
0
;
__test_callback_flags
=
0
;
test
(
"Calls disconnect callback and free callback on redisFree: "
);
test
(
"Calls disconnect callback and free callback on redisFree: "
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
redisSetDisconnectCallback
(
c
,
__test_callback
,(
const
void
*
)
2
);
redisSetDisconnectCallback
(
c
,
__test_callback
,(
void
*
)
2
);
redisSetFreeCallback
(
c
,
__test_callback
,(
const
void
*
)
4
);
redisSetFreeCallback
(
c
,
__test_callback
,(
void
*
)
4
);
redisFree
(
c
);
redisFree
(
c
);
test_cond
(
__test_callback_flags
==
((
2
<<
8
)
|
4
));
test_cond
(
__test_callback_flags
==
((
2
<<
8
)
|
4
));
...
@@ -262,9 +262,9 @@ static void test_nonblocking_connection() {
...
@@ -262,9 +262,9 @@ static void test_nonblocking_connection() {
wdone
=
__test_reply_callback_flags
=
0
;
wdone
=
__test_reply_callback_flags
=
0
;
test
(
"Process callbacks in the right sequence: "
);
test
(
"Process callbacks in the right sequence: "
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
const
void
*
)
1
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
void
*
)
1
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
const
void
*
)
2
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
void
*
)
2
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
const
void
*
)
3
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
void
*
)
3
,
"PING"
);
/* Write output buffer */
/* Write output buffer */
while
(
!
wdone
)
{
while
(
!
wdone
)
{
...
...
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