Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
93ca5ebc
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,发现更多精彩内容 >>
提交
93ca5ebc
编写于
4月 26, 2013
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core::rt: Clean up the interface to rtio
Make names that better match rt::io. Return error types.
上级
b2fbd346
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
63 addition
and
60 deletion
+63
-60
src/libcore/rt/io/mod.rs
src/libcore/rt/io/mod.rs
+1
-0
src/libcore/rt/io/net/tcp.rs
src/libcore/rt/io/net/tcp.rs
+12
-11
src/libcore/rt/rtio.rs
src/libcore/rt/rtio.rs
+9
-9
src/libcore/rt/uv/mod.rs
src/libcore/rt/uv/mod.rs
+1
-1
src/libcore/rt/uvio.rs
src/libcore/rt/uvio.rs
+40
-39
未找到文件。
src/libcore/rt/io/mod.rs
浏览文件 @
93ca5ebc
...
...
@@ -238,6 +238,7 @@
* How does I/O relate to the Iterator trait?
* std::base64 filters
* Using conditions is a big unknown since we don't have much experience with them
* Too many uses of OtherIoError
*/
...
...
src/libcore/rt/io/net/tcp.rs
浏览文件 @
93ca5ebc
...
...
@@ -9,21 +9,22 @@
// except according to those terms.
use
option
::{
Option
,
Some
,
None
};
use
result
::{
Result
,
Ok
,
Err
};
use
result
::{
Ok
,
Err
};
use
ops
::
Drop
;
use
rt
::
sched
::
local_sched
::
unsafe_borrow_io
;
use
rt
::
io
::
net
::
ip
::
IpAddr
;
use
rt
::
io
::{
Reader
,
Writer
,
Listener
};
use
rt
::
io
::
io_error
;
use
rt
::
rtio
;
use
rt
::
rtio
::{
IoFactory
,
TcpListener
,
Stream
};
use
rt
::
rtio
::{
IoFactory
,
RtioTcpListener
,
RtioTcpListenerObject
,
RtioTcpStream
,
RtioTcpStreamObject
};
pub
struct
TcpStream
{
rtstream
:
~
rtio
::
StreamObject
rtstream
:
~
RtioTcp
StreamObject
}
impl
TcpStream
{
fn
new
(
s
:
~
rtio
::
StreamObject
)
->
TcpStream
{
fn
new
(
s
:
~
RtioTcp
StreamObject
)
->
TcpStream
{
TcpStream
{
rtstream
:
s
}
...
...
@@ -34,7 +35,7 @@ pub fn connect(addr: IpAddr) -> Option<TcpStream> {
rtdebug!
(
"borrowing io to connect"
);
let
io
=
unsafe_borrow_io
();
rtdebug!
(
"about to connect"
);
io
.connect
(
addr
)
io
.
tcp_
connect
(
addr
)
};
match
stream
{
...
...
@@ -85,12 +86,12 @@ fn finalize(&self) {
}
pub
struct
TcpListener
{
rtlistener
:
~
rtio
::
TcpListenerObject
rtlistener
:
~
Rtio
TcpListenerObject
}
impl
TcpListener
{
pub
fn
bind
(
addr
:
IpAddr
)
->
Option
<
TcpListener
>
{
let
listener
=
unsafe
{
unsafe_borrow_io
()
.bind
(
addr
)
};
let
listener
=
unsafe
{
unsafe_borrow_io
()
.
tcp_
bind
(
addr
)
};
match
listener
{
Ok
(
l
)
=>
{
Some
(
TcpListener
{
...
...
@@ -107,12 +108,12 @@ pub fn bind(addr: IpAddr) -> Option<TcpListener> {
impl
Listener
<
TcpStream
>
for
TcpListener
{
fn
accept
(
&
mut
self
)
->
Option
<
TcpStream
>
{
let
rtstream
=
self
.rtlistener
.
listen
();
let
rtstream
=
self
.rtlistener
.
accept
();
match
rtstream
{
Some
(
s
)
=>
{
Ok
(
s
)
=>
{
Some
(
TcpStream
::
new
(
s
))
}
None
=>
{
Err
(
_
)
=>
{
abort!
(
"TODO"
);
}
}
...
...
src/libcore/rt/rtio.rs
浏览文件 @
93ca5ebc
...
...
@@ -18,8 +18,8 @@
// types to use instead
pub
type
EventLoopObject
=
super
::
uvio
::
UvEventLoop
;
pub
type
IoFactoryObject
=
super
::
uvio
::
UvIoFactory
;
pub
type
StreamObject
=
super
::
uvio
::
Uv
Stream
;
pub
type
TcpListenerObject
=
super
::
uvio
::
UvTcpListener
;
pub
type
RtioTcpStreamObject
=
super
::
uvio
::
UvTcp
Stream
;
pub
type
Rtio
TcpListenerObject
=
super
::
uvio
::
UvTcpListener
;
pub
trait
EventLoop
{
fn
run
(
&
mut
self
);
...
...
@@ -29,15 +29,15 @@ pub trait EventLoop {
}
pub
trait
IoFactory
{
fn
connect
(
&
mut
self
,
addr
:
IpAddr
)
->
Result
<~
StreamObject
,
IoError
>
;
fn
bind
(
&
mut
self
,
addr
:
IpAddr
)
->
Result
<~
TcpListenerObject
,
IoError
>
;
fn
tcp_connect
(
&
mut
self
,
addr
:
IpAddr
)
->
Result
<~
RtioTcp
StreamObject
,
IoError
>
;
fn
tcp_bind
(
&
mut
self
,
addr
:
IpAddr
)
->
Result
<~
Rtio
TcpListenerObject
,
IoError
>
;
}
pub
trait
TcpListener
{
fn
listen
(
&
mut
self
)
->
Option
<~
StreamObject
>
;
pub
trait
Rtio
TcpListener
{
fn
accept
(
&
mut
self
)
->
Result
<~
RtioTcpStreamObject
,
IoError
>
;
}
pub
trait
Stream
{
fn
read
(
&
mut
self
,
buf
:
&
mut
[
u8
])
->
Result
<
uint
,
()
>
;
fn
write
(
&
mut
self
,
buf
:
&
[
u8
])
->
Result
<
(),
()
>
;
pub
trait
RtioTcp
Stream
{
fn
read
(
&
mut
self
,
buf
:
&
mut
[
u8
])
->
Result
<
uint
,
IoError
>
;
fn
write
(
&
mut
self
,
buf
:
&
[
u8
])
->
Result
<
(),
IoError
>
;
}
src/libcore/rt/uv/mod.rs
浏览文件 @
93ca5ebc
...
...
@@ -48,7 +48,7 @@
use
unstable
::
finally
::
Finally
;
use
rt
::
uvll
;
use
rt
::
io
::
{
IoError
,
FileNotFound
}
;
use
rt
::
io
::
IoError
;
#[cfg(test)]
use
unstable
::
run_in_bare_thread
;
...
...
src/libcore/rt/uvio.rs
浏览文件 @
93ca5ebc
...
...
@@ -10,19 +10,20 @@
use
option
::
*
;
use
result
::
*
;
use
rt
::
io
::
IoError
;
use
super
::
io
::
net
::
ip
::
IpAddr
;
use
super
::
uv
::
*
;
use
super
::
rtio
::
*
;
use
ops
::
Drop
;
use
cell
::{
Cell
,
empty_cell
};
use
cast
::
transmute
;
use
super
::
sched
::{
Scheduler
,
local_sched
};
use
rt
::
io
::
IoError
;
use
rt
::
io
::
net
::
ip
::
IpAddr
;
use
rt
::
uv
::
*
;
use
rt
::
rtio
::
*
;
use
rt
::
sched
::{
Scheduler
,
local_sched
};
use
rt
::
io
::{
standard_error
,
OtherIoError
};
#[cfg(test)]
use
uint
;
#[cfg(test)]
use
unstable
::
run_in_bare_thread
;
#[cfg(test)]
use
super
::
test
::
*
;
#[cfg(test)]
use
rt
::
test
::
*
;
pub
struct
UvEventLoop
{
uvio
:
UvIoFactory
...
...
@@ -99,11 +100,11 @@ impl IoFactory for UvIoFactory {
// Connect to an address and return a new stream
// NB: This blocks the task waiting on the connection.
// It would probably be better to return a future
fn
connect
(
&
mut
self
,
addr
:
IpAddr
)
->
Result
<~
StreamObject
,
IoError
>
{
fn
tcp_connect
(
&
mut
self
,
addr
:
IpAddr
)
->
Result
<~
RtioTcp
StreamObject
,
IoError
>
{
// Create a cell in the task to hold the result. We will fill
// the cell before resuming the task.
let
result_cell
=
empty_cell
();
let
result_cell_ptr
:
*
Cell
<
Result
<~
StreamObject
,
IoError
>>
=
&
result_cell
;
let
result_cell_ptr
:
*
Cell
<
Result
<~
RtioTcp
StreamObject
,
IoError
>>
=
&
result_cell
;
let
scheduler
=
local_sched
::
take
();
assert
!
(
scheduler
.in_task_context
());
...
...
@@ -123,7 +124,7 @@ fn connect(&mut self, addr: IpAddr) -> Result<~StreamObject, IoError> {
rtdebug!
(
"connect: in connect callback"
);
let
maybe_stream
=
if
status
.is_none
()
{
rtdebug!
(
"status is none"
);
Ok
(
~
UvStream
(
stream_watcher
))
Ok
(
~
Uv
Tcp
Stream
(
stream_watcher
))
}
else
{
rtdebug!
(
"status is some"
);
// XXX: Wait for close
...
...
@@ -144,7 +145,7 @@ fn connect(&mut self, addr: IpAddr) -> Result<~StreamObject, IoError> {
return
result_cell
.take
();
}
fn
bind
(
&
mut
self
,
addr
:
IpAddr
)
->
Result
<~
TcpListenerObject
,
IoError
>
{
fn
tcp_bind
(
&
mut
self
,
addr
:
IpAddr
)
->
Result
<~
Rtio
TcpListenerObject
,
IoError
>
{
let
mut
watcher
=
TcpWatcher
::
new
(
self
.uv_loop
());
match
watcher
.bind
(
addr
)
{
Ok
(
_
)
=>
Ok
(
~
UvTcpListener
(
watcher
)),
...
...
@@ -177,12 +178,12 @@ fn finalize(&self) {
}
}
impl
TcpListener
for
UvTcpListener
{
impl
Rtio
TcpListener
for
UvTcpListener
{
fn
listen
(
&
mut
self
)
->
Option
<~
StreamObject
>
{
fn
accept
(
&
mut
self
)
->
Result
<~
RtioTcpStreamObject
,
IoError
>
{
rtdebug!
(
"entering listen"
);
let
result_cell
=
empty_cell
();
let
result_cell_ptr
:
*
Cell
<
Option
<~
StreamObject
>>
=
&
result_cell
;
let
result_cell_ptr
:
*
Cell
<
Result
<~
RtioTcpStreamObject
,
IoError
>>
=
&
result_cell
;
let
server_tcp_watcher
=
self
.watcher
();
...
...
@@ -199,9 +200,9 @@ fn listen(&mut self) -> Option<~StreamObject> {
let
client_tcp_watcher
=
TcpWatcher
::
new
(
&
mut
loop_
)
.as_stream
();
// XXX: Needs to be surfaced in interface
server_stream_watcher
.accept
(
client_tcp_watcher
);
Some
(
~
Uv
Stream
::
new
(
client_tcp_watcher
))
Ok
(
~
UvTcp
Stream
::
new
(
client_tcp_watcher
))
}
else
{
None
Err
(
standard_error
(
OtherIoError
))
};
unsafe
{
(
*
result_cell_ptr
)
.put_back
(
maybe_stream
);
}
...
...
@@ -218,15 +219,15 @@ fn listen(&mut self) -> Option<~StreamObject> {
}
}
pub
struct
UvStream
(
StreamWatcher
);
pub
struct
Uv
Tcp
Stream
(
StreamWatcher
);
impl
UvStream
{
fn
new
(
watcher
:
StreamWatcher
)
->
UvStream
{
UvStream
(
watcher
)
impl
Uv
Tcp
Stream
{
fn
new
(
watcher
:
StreamWatcher
)
->
Uv
Tcp
Stream
{
Uv
Tcp
Stream
(
watcher
)
}
fn
watcher
(
&
self
)
->
StreamWatcher
{
match
self
{
&
UvStream
(
w
)
=>
w
}
match
self
{
&
Uv
Tcp
Stream
(
w
)
=>
w
}
}
// XXX: finalize isn't working for ~UvStream???
...
...
@@ -236,17 +237,17 @@ fn close(&self) {
}
}
impl
Drop
for
UvStream
{
impl
Drop
for
Uv
Tcp
Stream
{
fn
finalize
(
&
self
)
{
rtdebug!
(
"closing stream"
);
//self.watcher().close(||());
}
}
impl
Stream
for
Uv
Stream
{
fn
read
(
&
mut
self
,
buf
:
&
mut
[
u8
])
->
Result
<
uint
,
()
>
{
impl
RtioTcpStream
for
UvTcp
Stream
{
fn
read
(
&
mut
self
,
buf
:
&
mut
[
u8
])
->
Result
<
uint
,
IoError
>
{
let
result_cell
=
empty_cell
();
let
result_cell_ptr
:
*
Cell
<
Result
<
uint
,
()
>>
=
&
result_cell
;
let
result_cell_ptr
:
*
Cell
<
Result
<
uint
,
IoError
>>
=
&
result_cell
;
let
scheduler
=
local_sched
::
take
();
assert
!
(
scheduler
.in_task_context
());
...
...
@@ -277,7 +278,7 @@ fn read(&mut self, buf: &mut [u8]) -> Result<uint, ()> {
assert
!
(
nread
>=
0
);
Ok
(
nread
as
uint
)
}
else
{
Err
(
(
))
Err
(
standard_error
(
OtherIoError
))
};
unsafe
{
(
*
result_cell_ptr
)
.put_back
(
result
);
}
...
...
@@ -291,9 +292,9 @@ fn read(&mut self, buf: &mut [u8]) -> Result<uint, ()> {
return
result_cell
.take
();
}
fn
write
(
&
mut
self
,
buf
:
&
[
u8
])
->
Result
<
(),
()
>
{
fn
write
(
&
mut
self
,
buf
:
&
[
u8
])
->
Result
<
(),
IoError
>
{
let
result_cell
=
empty_cell
();
let
result_cell_ptr
:
*
Cell
<
Result
<
(),
()
>>
=
&
result_cell
;
let
result_cell_ptr
:
*
Cell
<
Result
<
(),
IoError
>>
=
&
result_cell
;
let
scheduler
=
local_sched
::
take
();
assert
!
(
scheduler
.in_task_context
());
let
watcher
=
self
.watcher
();
...
...
@@ -308,7 +309,7 @@ fn write(&mut self, buf: &[u8]) -> Result<(), ()> {
let
result
=
if
status
.is_none
()
{
Ok
(())
}
else
{
Err
(
(
))
Err
(
standard_error
(
OtherIoError
))
};
unsafe
{
(
*
result_cell_ptr
)
.put_back
(
result
);
}
...
...
@@ -328,7 +329,7 @@ fn test_simple_io_no_connect() {
do
run_in_newsched_task
{
let
io
=
unsafe
{
local_sched
::
unsafe_borrow_io
()
};
let
addr
=
next_test_ip4
();
let
maybe_chan
=
io
.connect
(
addr
);
let
maybe_chan
=
io
.
tcp_
connect
(
addr
);
assert
!
(
maybe_chan
.is_err
());
}
}
...
...
@@ -342,8 +343,8 @@ fn test_simple_tcp_server_and_client() {
do
spawntask_immediately
{
unsafe
{
let
io
=
local_sched
::
unsafe_borrow_io
();
let
mut
listener
=
io
.bind
(
addr
)
.unwrap
();
let
mut
stream
=
listener
.
listen
()
.unwrap
();
let
mut
listener
=
io
.
tcp_
bind
(
addr
)
.unwrap
();
let
mut
stream
=
listener
.
accept
()
.unwrap
();
let
mut
buf
=
[
0
,
..
2048
];
let
nread
=
stream
.read
(
buf
)
.unwrap
();
assert
!
(
nread
==
8
);
...
...
@@ -359,7 +360,7 @@ fn test_simple_tcp_server_and_client() {
do
spawntask_immediately
{
unsafe
{
let
io
=
local_sched
::
unsafe_borrow_io
();
let
mut
stream
=
io
.connect
(
addr
)
.unwrap
();
let
mut
stream
=
io
.
tcp_
connect
(
addr
)
.unwrap
();
stream
.write
([
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
]);
stream
.close
();
}
...
...
@@ -374,8 +375,8 @@ fn test_read_and_block() {
do
spawntask_immediately
{
let
io
=
unsafe
{
local_sched
::
unsafe_borrow_io
()
};
let
mut
listener
=
io
.bind
(
addr
)
.unwrap
();
let
mut
stream
=
listener
.
listen
()
.unwrap
();
let
mut
listener
=
io
.
tcp_
bind
(
addr
)
.unwrap
();
let
mut
stream
=
listener
.
accept
()
.unwrap
();
let
mut
buf
=
[
0
,
..
2048
];
let
expected
=
32
;
...
...
@@ -412,7 +413,7 @@ fn test_read_and_block() {
do
spawntask_immediately
{
let
io
=
unsafe
{
local_sched
::
unsafe_borrow_io
()
};
let
mut
stream
=
io
.connect
(
addr
)
.unwrap
();
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
]);
stream
.write
([
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
]);
...
...
@@ -432,8 +433,8 @@ fn test_read_read_read() {
do
spawntask_immediately
{
unsafe
{
let
io
=
local_sched
::
unsafe_borrow_io
();
let
mut
listener
=
io
.bind
(
addr
)
.unwrap
();
let
mut
stream
=
listener
.
listen
()
.unwrap
();
let
mut
listener
=
io
.
tcp_
bind
(
addr
)
.unwrap
();
let
mut
stream
=
listener
.
accept
()
.unwrap
();
let
mut
buf
=
[
1
,
..
2048
];
let
mut
total_bytes_written
=
0
;
while
total_bytes_written
<
MAX
{
...
...
@@ -447,7 +448,7 @@ fn test_read_read_read() {
do
spawntask_immediately
{
let
io
=
unsafe
{
local_sched
::
unsafe_borrow_io
()
};
let
mut
stream
=
io
.connect
(
addr
)
.unwrap
();
let
mut
stream
=
io
.
tcp_
connect
(
addr
)
.unwrap
();
let
mut
buf
=
[
0
,
..
2048
];
let
mut
total_bytes_read
=
0
;
while
total_bytes_read
<
MAX
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录