Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c301db20
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c301db20
编写于
7月 15, 2014
作者:
A
Alex Crichton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
native: Add some documentation for accept
Document the new code for how close_accept and timeouts are implemented.
上级
7441d4f3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
0 deletion
+34
-0
src/libnative/io/net.rs
src/libnative/io/net.rs
+34
-0
未找到文件。
src/libnative/io/net.rs
浏览文件 @
c301db20
...
...
@@ -526,6 +526,20 @@ pub fn fd(&self) -> sock_t { self.inner.listener.fd() }
#[cfg(unix)]
pub
fn
native_accept
(
&
mut
self
)
->
IoResult
<
TcpStream
>
{
// In implementing accept, the two main concerns are dealing with
// close_accept() and timeouts. The unix implementation is based on a
// nonblocking accept plus a call to select(). Windows ends up having
// an entirely separate implementation than unix, which is explained
// below.
//
// To implement timeouts, all blocking is done via select() instead of
// accept() by putting the socket in non-blocking mode. Because
// select() takes a timeout argument, we just pass through the timeout
// to select().
//
// To implement close_accept(), we have a self-pipe to ourselves which
// is passed to select() along with the socket being accepted on. The
// self-pipe is never written to unless close_accept() is called.
let
deadline
=
if
self
.deadline
==
0
{
None
}
else
{
Some
(
self
.deadline
)};
while
!
self
.inner.closed
.load
(
atomics
::
SeqCst
)
{
...
...
@@ -545,6 +559,26 @@ pub fn native_accept(&mut self) -> IoResult<TcpStream> {
#[cfg(windows)]
pub
fn
native_accept
(
&
mut
self
)
->
IoResult
<
TcpStream
>
{
// Unlink unix, windows cannot invoke `select` on arbitrary file
// descriptors like pipes, only sockets. Consequently, windows cannot
// use the same implementation as unix for accept() when close_accept()
// is considered.
//
// In order to implement close_accept() and timeouts, windows uses
// event handles. An acceptor-specific abort event is created which
// will only get set in close_accept(), and it will never be un-set.
// Additionally, another acceptor-specific event is associated with the
// FD_ACCEPT network event.
//
// These two events are then passed to WaitForMultipleEvents to see
// which one triggers first, and the timeout passed to this function is
// the local timeout for the acceptor.
//
// If the wait times out, then the accept timed out. If the wait
// succeeds with the abort event, then we were closed, and if the wait
// succeeds otherwise, then we do a nonblocking poll via `accept` to
// see if we can accept a connection. The connection is candidate to be
// stolen, so we do all of this in a loop as well.
let
events
=
[
self
.inner.abort
.handle
(),
self
.inner.accept
.handle
()];
while
!
self
.inner.closed
.load
(
atomics
::
SeqCst
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录