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
redis
Commits
354a5de2
Commit
354a5de2
authored
Sep 03, 2013
by
antirez
Browse files
Cluster: clusterReadHandler() reworked to be more correct and simpler to follow.
parent
1036b4b2
Changes
1
Show whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
354a5de2
...
@@ -1169,7 +1169,7 @@ void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -1169,7 +1169,7 @@ void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
REDIS_NOTUSED
(
el
);
REDIS_NOTUSED
(
el
);
REDIS_NOTUSED
(
mask
);
REDIS_NOTUSED
(
mask
);
again:
while
(
1
)
{
/* Read as long as there is data to read. */
rcvbuflen
=
sdslen
(
link
->
rcvbuf
);
rcvbuflen
=
sdslen
(
link
->
rcvbuf
);
if
(
rcvbuflen
<
4
)
{
if
(
rcvbuflen
<
4
)
{
/* First, obtain the first four bytes to get the full message
/* First, obtain the first four bytes to get the full message
...
@@ -1188,6 +1188,7 @@ again:
...
@@ -1188,6 +1188,7 @@ again:
}
}
}
}
readlen
=
ntohl
(
hdr
->
totlen
)
-
rcvbuflen
;
readlen
=
ntohl
(
hdr
->
totlen
)
-
rcvbuflen
;
if
(
readlen
>
sizeof
(
buf
))
readlen
=
sizeof
(
buf
);
}
}
nread
=
read
(
fd
,
buf
,
readlen
);
nread
=
read
(
fd
,
buf
,
readlen
);
...
@@ -1206,16 +1207,14 @@ again:
...
@@ -1206,16 +1207,14 @@ again:
rcvbuflen
+=
nread
;
rcvbuflen
+=
nread
;
}
}
/* Total length obtained? read the payload now instead of burning
/* Total length obtained? Process this packet. */
* cycles waiting for a new event to fire. */
if
(
rcvbuflen
>=
4
&&
rcvbuflen
==
ntohl
(
hdr
->
totlen
))
{
if
(
rcvbuflen
==
4
)
goto
again
;
/* Whole packet in memory? We can process it. */
if
(
rcvbuflen
==
ntohl
(
hdr
->
totlen
))
{
if
(
clusterProcessPacket
(
link
))
{
if
(
clusterProcessPacket
(
link
))
{
sdsfree
(
link
->
rcvbuf
);
sdsfree
(
link
->
rcvbuf
);
link
->
rcvbuf
=
sdsempty
();
link
->
rcvbuf
=
sdsempty
();
rcvbuflen
=
0
;
/* Useless line of code currently... defensive. */
}
else
{
return
;
/* Link no longer valid. */
}
}
}
}
}
}
}
...
...
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