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
073dc843
"alloc.h" did not exist on "e6d997a96f9af10f08c9c9e52fb545420650b05b"
Commit
073dc843
authored
Sep 30, 2016
by
Hyungjin Kim
Browse files
Counting pending subscribe. Fix #396
parent
5f98e1d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
async.c
View file @
073dc843
...
...
@@ -364,6 +364,7 @@ void redisAsyncDisconnect(redisAsyncContext *ac) {
static
int
__redisGetSubscribeCallback
(
redisAsyncContext
*
ac
,
redisReply
*
reply
,
redisCallback
*
dstcb
)
{
redisContext
*
c
=
&
(
ac
->
c
);
dict
*
callbacks
;
redisCallback
*
cb
;
dictEntry
*
de
;
int
pvariant
;
char
*
stype
;
...
...
@@ -387,16 +388,26 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply,
sname
=
sdsnewlen
(
reply
->
element
[
1
]
->
str
,
reply
->
element
[
1
]
->
len
);
de
=
dictFind
(
callbacks
,
sname
);
if
(
de
!=
NULL
)
{
cb
=
dictGetEntryVal
(
de
);
/* If this is an subscribe reply decrease pending counter. */
if
(
strcasecmp
(
stype
+
pvariant
,
"subscribe"
)
==
0
)
{
cb
->
pending_subs
-=
1
;
}
memcpy
(
dstcb
,
dictGetEntryVal
(
de
),
sizeof
(
*
dstcb
));
/* If this is an unsubscribe message, remove it. */
if
(
strcasecmp
(
stype
+
pvariant
,
"unsubscribe"
)
==
0
)
{
dictDelete
(
callbacks
,
sname
);
if
(
cb
->
pending_subs
==
0
)
dictDelete
(
callbacks
,
sname
);
/* If this was the last unsubscribe message, revert to
* non-subscribe mode. */
assert
(
reply
->
element
[
2
]
->
type
==
REDIS_REPLY_INTEGER
);
if
(
reply
->
element
[
2
]
->
integer
==
0
)
/* Unset subscribed flag only when no pipelined pending subscribe. */
if
(
reply
->
element
[
2
]
->
integer
==
0
&&
dictSize
(
callbacks
)
==
0
)
c
->
flags
&=
~
REDIS_SUBSCRIBED
;
}
}
...
...
@@ -410,7 +421,7 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply,
void
redisProcessCallbacks
(
redisAsyncContext
*
ac
)
{
redisContext
*
c
=
&
(
ac
->
c
);
redisCallback
cb
=
{
NULL
,
NULL
,
NULL
};
redisCallback
cb
=
{
NULL
,
NULL
,
0
,
NULL
};
void
*
reply
=
NULL
;
int
status
;
...
...
@@ -583,6 +594,9 @@ static const char *nextArgument(const char *start, const char **str, size_t *len
static
int
__redisAsyncCommand
(
redisAsyncContext
*
ac
,
redisCallbackFn
*
fn
,
void
*
privdata
,
const
char
*
cmd
,
size_t
len
)
{
redisContext
*
c
=
&
(
ac
->
c
);
redisCallback
cb
;
struct
dict
*
cbdict
;
dictEntry
*
de
;
redisCallback
*
existcb
;
int
pvariant
,
hasnext
;
const
char
*
cstr
,
*
astr
;
size_t
clen
,
alen
;
...
...
@@ -596,6 +610,7 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void
/* Setup callback */
cb
.
fn
=
fn
;
cb
.
privdata
=
privdata
;
cb
.
pending_subs
=
1
;
/* Find out which command will be appended. */
p
=
nextArgument
(
cmd
,
&
cstr
,
&
clen
);
...
...
@@ -612,9 +627,18 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void
while
((
p
=
nextArgument
(
p
,
&
astr
,
&
alen
))
!=
NULL
)
{
sname
=
sdsnewlen
(
astr
,
alen
);
if
(
pvariant
)
ret
=
dictReplace
(
ac
->
sub
.
patterns
,
sname
,
&
cb
)
;
cbdict
=
ac
->
sub
.
patterns
;
else
ret
=
dictReplace
(
ac
->
sub
.
channels
,
sname
,
&
cb
);
cbdict
=
ac
->
sub
.
channels
;
de
=
dictFind
(
cbdict
,
sname
);
if
(
de
!=
NULL
)
{
existcb
=
dictGetEntryVal
(
de
);
cb
.
pending_subs
=
existcb
->
pending_subs
+
1
;
}
ret
=
dictReplace
(
cbdict
,
sname
,
&
cb
);
if
(
ret
==
0
)
sdsfree
(
sname
);
}
...
...
async.h
View file @
073dc843
...
...
@@ -45,6 +45,7 @@ typedef void (redisCallbackFn)(struct redisAsyncContext*, void*, void*);
typedef
struct
redisCallback
{
struct
redisCallback
*
next
;
/* simple singly linked list */
redisCallbackFn
*
fn
;
int
pending_subs
;
void
*
privdata
;
}
redisCallback
;
...
...
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