Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
4ccf671c
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,发现更多精彩内容 >>
提交
4ccf671c
编写于
3月 31, 2012
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better syncio.c with millisecond resolution.
上级
88bd32f1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
19 deletion
+48
-19
src/redis.h
src/redis.h
+3
-3
src/syncio.c
src/syncio.c
+45
-16
未找到文件。
src/redis.h
浏览文件 @
4ccf671c
...
...
@@ -811,9 +811,9 @@ int equalStringObjects(robj *a, robj *b);
unsigned
long
estimateObjectIdleTime
(
robj
*
o
);
/* Synchronous I/O with timeout */
int
syncWrite
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
int
timeout
);
int
syncRead
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
int
timeout
);
int
syncReadLine
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
int
timeout
);
ssize_t
syncWrite
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
long
long
timeout
);
ssize_t
syncRead
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
long
long
timeout
);
ssize_t
syncReadLine
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
long
long
timeout
);
/* Replication */
void
replicationFeedSlaves
(
list
*
slaves
,
int
dictid
,
robj
**
argv
,
int
argc
);
...
...
src/syncio.c
浏览文件 @
4ccf671c
...
...
@@ -36,50 +36,79 @@
* of the SYNC command where the slave does it in a blocking way, and
* the MIGRATE command that must be blocking in order to be atomic from the
* point of view of the two instances (one migrating the key and one receiving
* the key). This is why need the following blocking I/O functions. */
* the key). This is why need the following blocking I/O functions.
*
* All the functions take the timeout in milliseconds. */
#define REDIS_SYNCIO_RESOLUTION 10
/* Resolution in milliseconds */
int
syncWrite
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
int
timeout
)
{
/* Write the specified payload to 'fd'. If writing the whole payload will be done
* within 'timeout' milliseconds the operation succeeds and 'size' is returned.
* Otherwise the operation fails, -1 is returned, and an unspecified partial write
* could be performed against the file descriptor. */
ssize_t
syncWrite
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
long
long
timeout
)
{
ssize_t
nwritten
,
ret
=
size
;
time_t
start
=
time
(
NULL
);
long
long
start
=
mstime
();
long
long
remaining
=
timeout
;
timeout
++
;
while
(
size
)
{
if
(
aeWait
(
fd
,
AE_WRITABLE
,
1000
)
&
AE_WRITABLE
)
{
while
(
1
)
{
long
long
wait
=
(
remaining
>
REDIS_SYNCIO_RESOLUTION
)
?
remaining
:
REDIS_SYNCIO_RESOLUTION
;
long
long
elapsed
;
if
(
aeWait
(
fd
,
AE_WRITABLE
,
wait
)
&
AE_WRITABLE
)
{
nwritten
=
write
(
fd
,
ptr
,
size
);
if
(
nwritten
==
-
1
)
return
-
1
;
ptr
+=
nwritten
;
size
-=
nwritten
;
if
(
size
==
0
)
return
ret
;
}
if
((
time
(
NULL
)
-
start
)
>
timeout
)
{
elapsed
=
mstime
()
-
start
;
if
(
elapsed
>=
timeout
)
{
errno
=
ETIMEDOUT
;
return
-
1
;
}
remaining
=
timeout
-
elapsed
;
}
return
ret
;
}
int
syncRead
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
int
timeout
)
{
/* Read the specified amount of bytes from 'fd'. If all the bytes are read within
* 'timeout' milliseconds the operation succeed and 'size' is returned.
* Otherwise the operation fails, -1 is returned, and an unspecified amount of
* data could be read from the file descriptor. */
ssize_t
syncRead
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
long
long
timeout
)
{
ssize_t
nread
,
totread
=
0
;
time_t
start
=
time
(
NULL
);
long
long
start
=
mstime
();
long
long
remaining
=
timeout
;
timeout
++
;
while
(
size
)
{
if
(
aeWait
(
fd
,
AE_READABLE
,
1000
)
&
AE_READABLE
)
{
while
(
1
)
{
long
long
wait
=
(
remaining
>
REDIS_SYNCIO_RESOLUTION
)
?
remaining
:
REDIS_SYNCIO_RESOLUTION
;
long
long
elapsed
;
if
(
aeWait
(
fd
,
AE_READABLE
,
wait
)
&
AE_READABLE
)
{
nread
=
read
(
fd
,
ptr
,
size
);
if
(
nread
<=
0
)
return
-
1
;
ptr
+=
nread
;
size
-=
nread
;
totread
+=
nread
;
if
(
size
==
0
)
return
totread
;
}
if
((
time
(
NULL
)
-
start
)
>
timeout
)
{
elapsed
=
mstime
()
-
start
;
if
(
elapsed
>=
timeout
)
{
errno
=
ETIMEDOUT
;
return
-
1
;
}
remaining
=
timeout
-
elapsed
;
}
return
totread
;
}
int
syncReadLine
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
int
timeout
)
{
/* Read a line making sure that every char will not require more than 'timeout'
* milliseconds to be read.
*
* On success the number of bytes read is returned, otherwise -1.
* On success the string is always correctly terminated with a 0 byte. */
ssize_t
syncReadLine
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
long
long
timeout
)
{
ssize_t
nread
=
0
;
size
--
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录