Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a246e8fa
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,发现更多精彩内容 >>
提交
a246e8fa
编写于
5月 19, 2013
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core::rt: Convert unsafe_borrow_io to a Local impl
上级
20426962
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
18 deletion
+29
-18
src/libcore/rt/io/net/tcp.rs
src/libcore/rt/io/net/tcp.rs
+7
-4
src/libcore/rt/local.rs
src/libcore/rt/local.rs
+15
-0
src/libcore/rt/sched.rs
src/libcore/rt/sched.rs
+0
-6
src/libcore/rt/uv/uvio.rs
src/libcore/rt/uv/uvio.rs
+7
-8
未找到文件。
src/libcore/rt/io/net/tcp.rs
浏览文件 @
a246e8fa
...
...
@@ -10,13 +10,13 @@
use
option
::{
Option
,
Some
,
None
};
use
result
::{
Ok
,
Err
};
use
rt
::
sched
::
unsafe_borrow_io
;
use
rt
::
io
::
net
::
ip
::
IpAddr
;
use
rt
::
io
::{
Reader
,
Writer
,
Listener
};
use
rt
::
io
::{
io_error
,
read_error
,
EndOfFile
};
use
rt
::
rtio
::{
IoFactory
,
use
rt
::
rtio
::{
IoFactory
,
IoFactoryObject
,
RtioTcpListener
,
RtioTcpListenerObject
,
RtioTcpStream
,
RtioTcpStreamObject
};
use
rt
::
local
::
Local
;
pub
struct
TcpStream
{
rtstream
:
~
RtioTcpStreamObject
...
...
@@ -32,7 +32,7 @@ fn new(s: ~RtioTcpStreamObject) -> TcpStream {
pub
fn
connect
(
addr
:
IpAddr
)
->
Option
<
TcpStream
>
{
let
stream
=
unsafe
{
rtdebug!
(
"borrowing io to connect"
);
let
io
=
unsafe_borrow_io
();
let
io
=
Local
::
unsafe_borrow
::
<
IoFactoryObject
>
();
rtdebug!
(
"about to connect"
);
(
*
io
)
.tcp_connect
(
addr
)
};
...
...
@@ -88,7 +88,10 @@ pub struct TcpListener {
impl
TcpListener
{
pub
fn
bind
(
addr
:
IpAddr
)
->
Option
<
TcpListener
>
{
let
listener
=
unsafe
{
(
*
unsafe_borrow_io
())
.tcp_bind
(
addr
)
};
let
listener
=
unsafe
{
let
io
=
Local
::
unsafe_borrow
::
<
IoFactoryObject
>
();
(
*
io
)
.tcp_bind
(
addr
)
};
match
listener
{
Ok
(
l
)
=>
{
Some
(
TcpListener
{
...
...
src/libcore/rt/local.rs
浏览文件 @
a246e8fa
...
...
@@ -12,6 +12,7 @@
use
rt
::
sched
::
Scheduler
;
use
rt
::
task
::
Task
;
use
rt
::
local_ptr
;
use
rt
::
rtio
::{
EventLoop
,
IoFactoryObject
};
pub
trait
Local
{
fn
put
(
value
:
~
Self
);
...
...
@@ -68,6 +69,20 @@ unsafe fn try_unsafe_borrow() -> Option<*mut Task> {
}
}
// XXX: This formulation won't work once ~IoFactoryObject is a real trait pointer
impl
Local
for
IoFactoryObject
{
fn
put
(
value
:
~
IoFactoryObject
)
{
abort!
(
"unimpl"
)
}
fn
take
()
->
~
IoFactoryObject
{
abort!
(
"unimpl"
)
}
fn
exists
()
->
bool
{
abort!
(
"unimpl"
)
}
fn
borrow
(
f
:
&
fn
(
&
mut
IoFactoryObject
))
{
abort!
(
"unimpl"
)
}
unsafe
fn
unsafe_borrow
()
->
*
mut
IoFactoryObject
{
let
sched
=
Local
::
unsafe_borrow
::
<
Scheduler
>
();
let
io
:
*
mut
IoFactoryObject
=
(
*
sched
)
.event_loop
.io
()
.unwrap
();
return
io
;
}
unsafe
fn
try_unsafe_borrow
()
->
Option
<*
mut
IoFactoryObject
>
{
abort!
(
"unimpl"
)
}
}
#[cfg(test)]
mod
test
{
use
rt
::
sched
::
Scheduler
;
...
...
src/libcore/rt/sched.rs
浏览文件 @
a246e8fa
...
...
@@ -401,12 +401,6 @@ fn recycle(~self, stack_pool: &mut StackPool) {
}
}
pub
unsafe
fn
unsafe_borrow_io
()
->
*
mut
IoFactoryObject
{
let
sched
=
Local
::
unsafe_borrow
::
<
Scheduler
>
();
let
io
:
*
mut
IoFactoryObject
=
(
*
sched
)
.event_loop
.io
()
.unwrap
();
return
io
;
}
#[cfg(test)]
mod
test
{
use
int
;
...
...
src/libcore/rt/uv/uvio.rs
浏览文件 @
a246e8fa
...
...
@@ -19,7 +19,6 @@
use
rt
::
uv
::
*
;
use
rt
::
uv
::
idle
::
IdleWatcher
;
use
rt
::
rtio
::
*
;
use
rt
::
sched
::
unsafe_borrow_io
;
use
rt
::
sched
::
Scheduler
;
use
rt
::
io
::{
standard_error
,
OtherIoError
};
use
rt
::
tube
::
Tube
;
...
...
@@ -359,7 +358,7 @@ fn write(&mut self, buf: &[u8]) -> Result<(), IoError> {
fn
test_simple_io_no_connect
()
{
do
run_in_newsched_task
{
unsafe
{
let
io
=
unsafe_borrow_io
();
let
io
=
Local
::
unsafe_borrow
::
<
IoFactoryObject
>
();
let
addr
=
next_test_ip4
();
let
maybe_chan
=
(
*
io
)
.tcp_connect
(
addr
);
assert
!
(
maybe_chan
.is_err
());
...
...
@@ -375,7 +374,7 @@ fn test_simple_tcp_server_and_client() {
// Start the server first so it's listening when we connect
do
spawntask_immediately
{
unsafe
{
let
io
=
unsafe_borrow_io
();
let
io
=
Local
::
unsafe_borrow
::
<
IoFactoryObject
>
();
let
mut
listener
=
(
*
io
)
.tcp_bind
(
addr
)
.unwrap
();
let
mut
stream
=
listener
.accept
()
.unwrap
();
let
mut
buf
=
[
0
,
..
2048
];
...
...
@@ -390,7 +389,7 @@ fn test_simple_tcp_server_and_client() {
do
spawntask_immediately
{
unsafe
{
let
io
=
unsafe_borrow_io
();
let
io
=
Local
::
unsafe_borrow
::
<
IoFactoryObject
>
();
let
mut
stream
=
(
*
io
)
.tcp_connect
(
addr
)
.unwrap
();
stream
.write
([
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
]);
}
...
...
@@ -404,7 +403,7 @@ fn test_read_and_block() {
let
addr
=
next_test_ip4
();
do
spawntask_immediately
{
let
io
=
unsafe
{
unsafe_borrow_io
()
};
let
io
=
unsafe
{
Local
::
unsafe_borrow
::
<
IoFactoryObject
>
()
};
let
mut
listener
=
unsafe
{
(
*
io
)
.tcp_bind
(
addr
)
.unwrap
()
};
let
mut
stream
=
listener
.accept
()
.unwrap
();
let
mut
buf
=
[
0
,
..
2048
];
...
...
@@ -440,7 +439,7 @@ fn test_read_and_block() {
do
spawntask_immediately
{
unsafe
{
let
io
=
unsafe_borrow_io
();
let
io
=
Local
::
unsafe_borrow
::
<
IoFactoryObject
>
();
let
mut
stream
=
(
*
io
)
.tcp_connect
(
addr
)
.unwrap
();
stream
.write
([
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
]);
stream
.write
([
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
]);
...
...
@@ -460,7 +459,7 @@ fn test_read_read_read() {
do
spawntask_immediately
{
unsafe
{
let
io
=
unsafe_borrow_io
();
let
io
=
Local
::
unsafe_borrow
::
<
IoFactoryObject
>
();
let
mut
listener
=
(
*
io
)
.tcp_bind
(
addr
)
.unwrap
();
let
mut
stream
=
listener
.accept
()
.unwrap
();
let
buf
=
[
1
,
..
2048
];
...
...
@@ -474,7 +473,7 @@ fn test_read_read_read() {
do
spawntask_immediately
{
unsafe
{
let
io
=
unsafe_borrow_io
();
let
io
=
Local
::
unsafe_borrow
::
<
IoFactoryObject
>
();
let
mut
stream
=
(
*
io
)
.tcp_connect
(
addr
)
.unwrap
();
let
mut
buf
=
[
0
,
..
2048
];
let
mut
total_bytes_read
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录