Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
libfastcommon
提交
7e1abd60
L
libfastcommon
项目概览
阿啄debugIT
/
libfastcommon
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libfastcommon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7e1abd60
编写于
6月 11, 2015
作者:
Y
yuqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ioevent support set timeout
上级
b3e37bd5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
7 deletion
+21
-7
src/ioevent.c
src/ioevent.c
+4
-6
src/ioevent.h
src/ioevent.h
+17
-1
未找到文件。
src/ioevent.c
浏览文件 @
7e1abd60
...
...
@@ -30,7 +30,7 @@ int kqueue_ev_convert(int16_t event, uint16_t flags)
#endif
int
ioevent_init
(
IOEventPoller
*
ioevent
,
const
int
size
,
const
int
timeout
,
const
int
extra_events
)
const
int
timeout
_ms
,
const
int
extra_events
)
{
int
bytes
;
...
...
@@ -40,26 +40,24 @@ int ioevent_init(IOEventPoller *ioevent, const int size,
ioevent
->
iterator
.
count
=
0
;
#if IOEVENT_USE_EPOLL
ioevent
->
timeout
=
timeout
;
ioevent
->
poll_fd
=
epoll_create
(
ioevent
->
size
);
bytes
=
sizeof
(
struct
epoll_event
)
*
size
;
ioevent
->
events
=
(
struct
epoll_event
*
)
malloc
(
bytes
);
#elif IOEVENT_USE_KQUEUE
ioevent
->
timeout
.
tv_sec
=
timeout
/
1000
;
ioevent
->
timeout
.
tv_nsec
=
1000000
*
(
timeout
%
1000
);
ioevent
->
poll_fd
=
kqueue
();
bytes
=
sizeof
(
struct
kevent
)
*
size
;
ioevent
->
events
=
(
struct
kevent
*
)
malloc
(
bytes
);
#elif IOEVENT_USE_PORT
ioevent
->
timeout
.
tv_sec
=
timeout
/
1000
;
ioevent
->
timeout
.
tv_nsec
=
1000000
*
(
timeout
%
1000
);
ioevent
->
poll_fd
=
port_create
();
bytes
=
sizeof
(
port_event_t
)
*
size
;
ioevent
->
events
=
(
port_event_t
*
)
malloc
(
bytes
);
#endif
if
(
ioevent
->
events
==
NULL
)
{
return
errno
!=
0
?
errno
:
ENOMEM
;
}
ioevent_set_timeout
(
ioevent
,
timeout_ms
);
return
0
;
}
...
...
src/ioevent.h
浏览文件 @
7e1abd60
...
...
@@ -113,7 +113,7 @@ extern "C" {
#endif
int
ioevent_init
(
IOEventPoller
*
ioevent
,
const
int
size
,
const
int
timeout
,
const
int
extra_events
);
const
int
timeout
_ms
,
const
int
extra_events
);
void
ioevent_destroy
(
IOEventPoller
*
ioevent
);
int
ioevent_attach
(
IOEventPoller
*
ioevent
,
const
int
fd
,
const
int
e
,
...
...
@@ -123,6 +123,22 @@ int ioevent_modify(IOEventPoller *ioevent, const int fd, const int e,
int
ioevent_detach
(
IOEventPoller
*
ioevent
,
const
int
fd
);
int
ioevent_poll
(
IOEventPoller
*
ioevent
);
static
inline
void
ioevent_set_timeout
(
IOEventPoller
*
ioevent
,
const
int
timeout_ms
)
{
#if IOEVENT_USE_EPOLL
ioevent
->
timeout
=
timeout_ms
;
#else
ioevent
->
timeout
.
tv_sec
=
timeout_ms
/
1000
;
ioevent
->
timeout
.
tv_nsec
=
1000000
*
(
timeout_ms
%
1000
);
#endif
}
static
inline
int
ioevent_poll_ex
(
IOEventPoller
*
ioevent
,
const
int
timeout_ms
)
{
ioevent_set_timeout
(
ioevent
,
timeout_ms
);
return
ioevent_poll
(
ioevent
);
}
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录