Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f01e2653
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,发现更多精彩内容 >>
提交
f01e2653
编写于
8月 22, 2013
作者:
J
Jeff Olson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
std: moved static file actions (open,unlink) to FsRequest
上级
f85d3b3e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
63 deletion
+63
-63
src/libstd/rt/uv/file.rs
src/libstd/rt/uv/file.rs
+61
-61
src/libstd/rt/uv/uvio.rs
src/libstd/rt/uv/uvio.rs
+2
-2
未找到文件。
src/libstd/rt/uv/file.rs
浏览文件 @
f01e2653
...
...
@@ -37,6 +37,58 @@ pub fn new(cb: Option<FsCallback>) -> FsRequest {
fs_req
}
fn
open_common
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
flags
:
int
,
mode
:
int
,
cb
:
Option
<
FsCallback
>
)
->
int
{
let
complete_cb_ptr
=
match
cb
{
Some
(
_
)
=>
compl_cb
as
*
u8
,
None
=>
0
as
*
u8
};
let
is_sync
=
cb
.is_none
();
let
req
=
FsRequest
::
new
(
cb
);
let
result
=
path
.path_as_str
(|
p
|
{
p
.to_c_str
()
.with_ref
(|
p
|
unsafe
{
uvll
::
fs_open
(
loop_
.native_handle
(),
req
.native_handle
(),
p
,
flags
,
mode
,
complete_cb_ptr
)
as
int
})
});
if
is_sync
{
req
.cleanup_and_delete
();
}
result
}
pub
fn
open
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
flags
:
int
,
mode
:
int
,
cb
:
FsCallback
)
{
FsRequest
::
open_common
(
loop_
,
path
,
flags
,
mode
,
Some
(
cb
));
}
pub
fn
open_sync
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
flags
:
int
,
mode
:
int
)
->
Result
<
int
,
UvError
>
{
let
result
=
FsRequest
::
open_common
(
loop_
,
path
,
flags
,
mode
,
None
);
sync_cleanup
(
&
loop_
,
result
)
}
fn
unlink_common
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
cb
:
Option
<
FsCallback
>
)
->
int
{
let
complete_cb_ptr
=
match
cb
{
Some
(
_
)
=>
compl_cb
as
*
u8
,
None
=>
0
as
*
u8
};
let
is_sync
=
cb
.is_none
();
let
req
=
FsRequest
::
new
(
cb
);
let
result
=
path
.path_as_str
(|
p
|
{
p
.to_c_str
()
.with_ref
(|
p
|
unsafe
{
uvll
::
fs_unlink
(
loop_
.native_handle
(),
req
.native_handle
(),
p
,
complete_cb_ptr
)
as
int
})
});
if
is_sync
{
req
.cleanup_and_delete
();
}
result
}
pub
fn
unlink
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
cb
:
FsCallback
)
{
let
result
=
FsRequest
::
unlink_common
(
loop_
,
path
,
Some
(
cb
));
sync_cleanup
(
&
loop_
,
result
);
}
pub
fn
unlink_sync
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
)
->
Result
<
int
,
UvError
>
{
let
result
=
FsRequest
::
unlink_common
(
loop_
,
path
,
None
);
sync_cleanup
(
&
loop_
,
result
)
}
pub
fn
install_req_data
(
&
self
,
cb
:
Option
<
FsCallback
>
)
{
let
fs_req
=
(
self
.native_handle
())
as
*
uvll
::
uv_write_t
;
let
data
=
~
RequestData
{
...
...
@@ -105,63 +157,11 @@ pub fn from_open_req(req: &mut FsRequest) -> FileDescriptor {
FileDescriptor
::
new
(
req
.get_result
())
}
fn
open_common
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
flags
:
int
,
mode
:
int
,
cb
:
Option
<
FsCallback
>
)
->
int
{
let
complete_cb_ptr
=
match
cb
{
Some
(
_
)
=>
compl_cb
,
None
=>
0
as
*
u8
};
let
is_sync
=
cb
.is_none
();
let
req
=
FsRequest
::
new
(
cb
);
let
result
=
path
.path_as_str
(|
p
|
{
p
.to_c_str
()
.with_ref
(|
p
|
unsafe
{
uvll
::
fs_open
(
loop_
.native_handle
(),
req
.native_handle
(),
p
,
flags
,
mode
,
complete_cb_ptr
)
as
int
})
});
if
is_sync
{
req
.cleanup_and_delete
();
}
result
}
pub
fn
open
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
flags
:
int
,
mode
:
int
,
cb
:
FsCallback
)
{
FileDescriptor
::
open_common
(
loop_
,
path
,
flags
,
mode
,
Some
(
cb
));
}
pub
fn
open_sync
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
flags
:
int
,
mode
:
int
)
->
Result
<
int
,
UvError
>
{
let
result
=
FileDescriptor
::
open_common
(
loop_
,
path
,
flags
,
mode
,
None
);
sync_cleanup
(
&
loop_
,
result
)
}
fn
unlink_common
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
cb
:
Option
<
FsCallback
>
)
->
int
{
let
complete_cb_ptr
=
match
cb
{
Some
(
_
)
=>
compl_cb
,
None
=>
0
as
*
u8
};
let
is_sync
=
cb
.is_none
();
let
req
=
FsRequest
::
new
(
cb
);
let
result
=
path
.path_as_str
(|
p
|
{
p
.to_c_str
()
.with_ref
(|
p
|
unsafe
{
uvll
::
fs_unlink
(
loop_
.native_handle
(),
req
.native_handle
(),
p
,
complete_cb_ptr
)
as
int
})
});
if
is_sync
{
req
.cleanup_and_delete
();
}
result
}
pub
fn
unlink
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
,
cb
:
FsCallback
)
{
let
result
=
FileDescriptor
::
unlink_common
(
loop_
,
path
,
Some
(
cb
));
sync_cleanup
(
&
loop_
,
result
);
}
pub
fn
unlink_sync
<
P
:
PathLike
>
(
loop_
:
Loop
,
path
:
&
P
)
->
Result
<
int
,
UvError
>
{
let
result
=
FileDescriptor
::
unlink_common
(
loop_
,
path
,
None
);
sync_cleanup
(
&
loop_
,
result
)
}
// as per bnoordhuis in #libuv: offset >= 0 uses prwrite instead of write
fn
write_common
(
&
mut
self
,
loop_
:
Loop
,
buf
:
Buf
,
offset
:
i64
,
cb
:
Option
<
FsCallback
>
)
->
int
{
let
complete_cb_ptr
=
match
cb
{
Some
(
_
)
=>
compl_cb
,
Some
(
_
)
=>
compl_cb
as
*
u8
,
None
=>
0
as
*
u8
};
let
is_sync
=
cb
.is_none
();
...
...
@@ -190,7 +190,7 @@ fn read_common(&mut self, loop_: Loop, buf: Buf,
offset
:
i64
,
cb
:
Option
<
FsCallback
>
)
->
int
{
let
complete_cb_ptr
=
match
cb
{
Some
(
_
)
=>
compl_cb
,
Some
(
_
)
=>
compl_cb
as
*
u8
,
None
=>
0
as
*
u8
};
let
is_sync
=
cb
.is_none
();
...
...
@@ -216,7 +216,7 @@ pub fn read_sync(&mut self, loop_: Loop, buf: Buf, offset: i64)
fn
close_common
(
self
,
loop_
:
Loop
,
cb
:
Option
<
FsCallback
>
)
->
int
{
let
complete_cb_ptr
=
match
cb
{
Some
(
_
)
=>
compl_cb
,
Some
(
_
)
=>
compl_cb
as
*
u8
,
None
=>
0
as
*
u8
};
let
is_sync
=
cb
.is_none
();
...
...
@@ -301,7 +301,7 @@ fn file_test_full_simple_impl() {
let
read_buf
=
slice_to_uv_buf
(
read_mem
);
let
read_buf_ptr
:
*
Buf
=
&
read_buf
;
let
p
=
Path
(
path_str
);
do
F
ileDescriptor
::
open
(
loop_
,
&
p
,
create_flags
as
int
,
mode
as
int
)
do
F
sRequest
::
open
(
loop_
,
&
p
,
create_flags
as
int
,
mode
as
int
)
|
req
,
uverr
|
{
let
loop_
=
req
.get_loop
();
assert
!
(
uverr
.is_none
());
...
...
@@ -313,7 +313,7 @@ fn file_test_full_simple_impl() {
do
fd
.close
(
loop_
)
|
req
,
_
|
{
let
loop_
=
req
.get_loop
();
assert
!
(
uverr
.is_none
());
do
F
ileDescriptor
::
open
(
loop_
,
&
Path
(
path_str
),
read_flags
as
int
,
0
)
do
F
sRequest
::
open
(
loop_
,
&
Path
(
path_str
),
read_flags
as
int
,
0
)
|
req
,
uverr
|
{
assert
!
(
uverr
.is_none
());
let
loop_
=
req
.get_loop
();
...
...
@@ -336,7 +336,7 @@ fn file_test_full_simple_impl() {
assert
!
(
read_str
==
~
"hello"
);
do
FileDescriptor
(
raw_fd
)
.close
(
loop_
)
|
_
,
uverr
|
{
assert
!
(
uverr
.is_none
());
do
F
ileDescriptor
::
unlink
(
loop_
,
&
Path
(
path_str
))
do
F
sRequest
::
unlink
(
loop_
,
&
Path
(
path_str
))
|
_
,
uverr
|
{
assert
!
(
uverr
.is_none
());
};
...
...
@@ -367,7 +367,7 @@ fn file_test_full_simple_impl_sync() {
let
write_val
=
"hello"
.as_bytes
()
.to_owned
();
let
write_buf
=
slice_to_uv_buf
(
write_val
);
// open/create
let
result
=
F
ileDescriptor
::
open_sync
(
loop_
,
&
Path
(
path_str
),
let
result
=
F
sRequest
::
open_sync
(
loop_
,
&
Path
(
path_str
),
create_flags
as
int
,
mode
as
int
);
assert
!
(
result
.is_ok
());
let
mut
fd
=
FileDescriptor
(
result
.unwrap
()
as
i32
);
...
...
@@ -378,7 +378,7 @@ fn file_test_full_simple_impl_sync() {
let
result
=
fd
.close_sync
(
loop_
);
assert
!
(
result
.is_ok
());
// re-open
let
result
=
F
ileDescriptor
::
open_sync
(
loop_
,
&
Path
(
path_str
),
let
result
=
F
sRequest
::
open_sync
(
loop_
,
&
Path
(
path_str
),
read_flags
as
int
,
0
);
assert
!
(
result
.is_ok
());
let
len
=
1028
;
...
...
@@ -399,7 +399,7 @@ fn file_test_full_simple_impl_sync() {
let
result
=
fd
.close_sync
(
loop_
);
assert
!
(
result
.is_ok
());
// unlink
let
result
=
F
ileDescriptor
::
unlink_sync
(
loop_
,
&
Path
(
path_str
));
let
result
=
F
sRequest
::
unlink_sync
(
loop_
,
&
Path
(
path_str
));
assert
!
(
result
.is_ok
());
}
else
{
fail
!
(
"nread was 0.. wudn't expectin' that."
);
}
loop_
.close
();
...
...
src/libstd/rt/uv/uvio.rs
浏览文件 @
f01e2653
...
...
@@ -477,7 +477,7 @@ fn fs_open<P: PathLike>(&mut self, path: &P, flags: int, mode: int)
do
scheduler
.deschedule_running_task_and_then
|
_
,
task
|
{
let
task_cell
=
Cell
::
new
(
task
);
let
path
=
path_cell
.take
();
do
file
::
F
ileDescriptor
::
open
(
loop_
,
path
,
flags
,
mode
)
|
req
,
err
|
{
do
file
::
F
sRequest
::
open
(
loop_
,
path
,
flags
,
mode
)
|
req
,
err
|
{
if
err
.is_none
()
{
let
home
=
get_handle_to_current_scheduler!
();
let
fd
=
file
::
FileDescriptor
(
req
.get_result
());
...
...
@@ -508,7 +508,7 @@ fn fs_unlink<P: PathLike>(&mut self, path: &P) -> Result<(), IoError> {
do
scheduler
.deschedule_running_task_and_then
|
_
,
task
|
{
let
task_cell
=
Cell
::
new
(
task
);
let
path
=
path_cell
.take
();
do
file
::
F
ileDescriptor
::
unlink
(
loop_
,
path
)
|
_
,
err
|
{
do
file
::
F
sRequest
::
unlink
(
loop_
,
path
)
|
_
,
err
|
{
let
res
=
match
err
{
None
=>
Ok
(()),
Some
(
err
)
=>
Err
(
uv_error_to_io_error
(
err
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录