Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
354a5de2
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
354a5de2
编写于
9月 03, 2013
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cluster: clusterReadHandler() reworked to be more correct and simpler to follow.
上级
1036b4b2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
43 deletion
+42
-43
src/cluster.c
src/cluster.c
+42
-43
未找到文件。
src/cluster.c
浏览文件 @
354a5de2
...
...
@@ -1169,53 +1169,52 @@ void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
REDIS_NOTUSED
(
el
);
REDIS_NOTUSED
(
mask
);
again:
rcvbuflen
=
sdslen
(
link
->
rcvbuf
);
if
(
rcvbuflen
<
4
)
{
/* First, obtain the first four bytes to get the full message
* length. */
readlen
=
4
-
rcvbuflen
;
}
else
{
/* Finally read the full message. */
hdr
=
(
clusterMsg
*
)
link
->
rcvbuf
;
if
(
rcvbuflen
==
4
)
{
/* Perform some sanity check on the message length. */
if
(
ntohl
(
hdr
->
totlen
)
<
CLUSTERMSG_MIN_LEN
)
{
redisLog
(
REDIS_WARNING
,
"Bad message length received from Cluster bus."
);
handleLinkIOError
(
link
);
return
;
while
(
1
)
{
/* Read as long as there is data to read. */
rcvbuflen
=
sdslen
(
link
->
rcvbuf
);
if
(
rcvbuflen
<
4
)
{
/* First, obtain the first four bytes to get the full message
* length. */
readlen
=
4
-
rcvbuflen
;
}
else
{
/* Finally read the full message. */
hdr
=
(
clusterMsg
*
)
link
->
rcvbuf
;
if
(
rcvbuflen
==
4
)
{
/* Perform some sanity check on the message length. */
if
(
ntohl
(
hdr
->
totlen
)
<
CLUSTERMSG_MIN_LEN
)
{
redisLog
(
REDIS_WARNING
,
"Bad message length received from Cluster bus."
);
handleLinkIOError
(
link
);
return
;
}
}
readlen
=
ntohl
(
hdr
->
totlen
)
-
rcvbuflen
;
if
(
readlen
>
sizeof
(
buf
))
readlen
=
sizeof
(
buf
);
}
readlen
=
ntohl
(
hdr
->
totlen
)
-
rcvbuflen
;
}
nread
=
read
(
fd
,
buf
,
readlen
);
if
(
nread
==
-
1
&&
errno
==
EAGAIN
)
return
;
/* No more data ready. */
nread
=
read
(
fd
,
buf
,
readlen
);
if
(
nread
==
-
1
&&
errno
==
EAGAIN
)
return
;
/* No more data ready. */
if
(
nread
<=
0
)
{
/* I/O error... */
redisLog
(
REDIS_DEBUG
,
"I/O error reading from node link: %s"
,
(
nread
==
0
)
?
"connection closed"
:
strerror
(
errno
));
handleLinkIOError
(
link
);
return
;
}
else
{
/* Read data and recast the pointer to the new buffer. */
link
->
rcvbuf
=
sdscatlen
(
link
->
rcvbuf
,
buf
,
nread
);
hdr
=
(
clusterMsg
*
)
link
->
rcvbuf
;
rcvbuflen
+=
nread
;
}
/* Total length obtained? read the payload now instead of burning
* cycles waiting for a new event to fire. */
if
(
rcvbuflen
==
4
)
goto
again
;
/* Whole packet in memory? We can process it. */
if
(
rcvbuflen
==
ntohl
(
hdr
->
totlen
))
{
if
(
clusterProcessPacket
(
link
))
{
sdsfree
(
link
->
rcvbuf
);
link
->
rcvbuf
=
sdsempty
();
rcvbuflen
=
0
;
/* Useless line of code currently... defensive. */
if
(
nread
<=
0
)
{
/* I/O error... */
redisLog
(
REDIS_DEBUG
,
"I/O error reading from node link: %s"
,
(
nread
==
0
)
?
"connection closed"
:
strerror
(
errno
));
handleLinkIOError
(
link
);
return
;
}
else
{
/* Read data and recast the pointer to the new buffer. */
link
->
rcvbuf
=
sdscatlen
(
link
->
rcvbuf
,
buf
,
nread
);
hdr
=
(
clusterMsg
*
)
link
->
rcvbuf
;
rcvbuflen
+=
nread
;
}
/* Total length obtained? Process this packet. */
if
(
rcvbuflen
>=
4
&&
rcvbuflen
==
ntohl
(
hdr
->
totlen
))
{
if
(
clusterProcessPacket
(
link
))
{
sdsfree
(
link
->
rcvbuf
);
link
->
rcvbuf
=
sdsempty
();
}
else
{
return
;
/* Link no longer valid. */
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录