Skip to content

Commit aa78c3d

Browse files
committed
Clean up the remaining chunks of uv
1 parent 584b359 commit aa78c3d

17 files changed

+105
-121
lines changed

src/librustuv/addrinfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::rt::local::Local;
1717
use std::rt::sched::Scheduler;
1818

1919
use net;
20-
use super::{Loop, UvError, NativeHandle, Request};
20+
use super::{Loop, UvError, Request};
2121
use uvll;
2222

2323
struct Addrinfo {
@@ -79,7 +79,7 @@ impl GetAddrInfoRequest {
7979
let req = Request::new(uvll::UV_GETADDRINFO);
8080

8181
return match unsafe {
82-
uvll::uv_getaddrinfo(loop_.native_handle(), req.handle,
82+
uvll::uv_getaddrinfo(loop_.handle, req.handle,
8383
getaddrinfo_cb, c_node_ptr, c_service_ptr,
8484
hint_ptr)
8585
} {

src/librustuv/async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl AsyncWatcher {
3535
pub fn new(loop_: &mut Loop, cb: ~Callback) -> AsyncWatcher {
3636
let handle = UvHandle::alloc(None::<AsyncWatcher>, uvll::UV_ASYNC);
3737
assert_eq!(unsafe {
38-
uvll::uv_async_init(loop_.native_handle(), handle, async_cb)
38+
uvll::uv_async_init(loop_.handle, handle, async_cb)
3939
}, 0);
4040
let flag = Exclusive::new(false);
4141
let payload = ~Payload { callback: cb, exit_flag: flag.clone() };

src/librustuv/file.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::rt::local::Local;
2222
use std::rt::sched::{Scheduler, SchedHandle};
2323
use std::vec;
2424

25-
use super::{NativeHandle, Loop, UvError, uv_error_to_io_error};
25+
use super::{Loop, UvError, uv_error_to_io_error};
2626
use uvio::HomingIO;
2727
use uvll;
2828

@@ -43,7 +43,7 @@ impl FsRequest {
4343
-> Result<FileWatcher, UvError>
4444
{
4545
execute(|req, cb| unsafe {
46-
uvll::uv_fs_open(loop_.native_handle(),
46+
uvll::uv_fs_open(loop_.handle,
4747
req, path.with_ref(|p| p), flags as c_int,
4848
mode as c_int, cb)
4949
}).map(|req|
@@ -54,21 +54,21 @@ impl FsRequest {
5454

5555
pub fn unlink(loop_: &Loop, path: &CString) -> Result<(), UvError> {
5656
execute_nop(|req, cb| unsafe {
57-
uvll::uv_fs_unlink(loop_.native_handle(), req, path.with_ref(|p| p),
57+
uvll::uv_fs_unlink(loop_.handle, req, path.with_ref(|p| p),
5858
cb)
5959
})
6060
}
6161

6262
pub fn lstat(loop_: &Loop, path: &CString) -> Result<FileStat, UvError> {
6363
execute(|req, cb| unsafe {
64-
uvll::uv_fs_lstat(loop_.native_handle(), req, path.with_ref(|p| p),
64+
uvll::uv_fs_lstat(loop_.handle, req, path.with_ref(|p| p),
6565
cb)
6666
}).map(|req| req.mkstat())
6767
}
6868

6969
pub fn stat(loop_: &Loop, path: &CString) -> Result<FileStat, UvError> {
7070
execute(|req, cb| unsafe {
71-
uvll::uv_fs_stat(loop_.native_handle(), req, path.with_ref(|p| p),
71+
uvll::uv_fs_stat(loop_.handle, req, path.with_ref(|p| p),
7272
cb)
7373
}).map(|req| req.mkstat())
7474
}
@@ -77,7 +77,7 @@ impl FsRequest {
7777
-> Result<(), UvError>
7878
{
7979
execute_nop(|req, cb| unsafe {
80-
uvll::uv_fs_write(loop_.native_handle(), req,
80+
uvll::uv_fs_write(loop_.handle, req,
8181
fd, vec::raw::to_ptr(buf) as *c_void,
8282
buf.len() as c_uint, offset, cb)
8383
})
@@ -87,7 +87,7 @@ impl FsRequest {
8787
-> Result<int, UvError>
8888
{
8989
do execute(|req, cb| unsafe {
90-
uvll::uv_fs_read(loop_.native_handle(), req,
90+
uvll::uv_fs_read(loop_.handle, req,
9191
fd, vec::raw::to_ptr(buf) as *c_void,
9292
buf.len() as c_uint, offset, cb)
9393
}).map |req| {
@@ -98,12 +98,12 @@ impl FsRequest {
9898
pub fn close(loop_: &Loop, fd: c_int, sync: bool) -> Result<(), UvError> {
9999
if sync {
100100
execute_nop(|req, cb| unsafe {
101-
uvll::uv_fs_close(loop_.native_handle(), req, fd, cb)
101+
uvll::uv_fs_close(loop_.handle, req, fd, cb)
102102
})
103103
} else {
104104
unsafe {
105105
let req = uvll::malloc_req(uvll::UV_FS);
106-
uvll::uv_fs_close(loop_.native_handle(), req, fd, close_cb);
106+
uvll::uv_fs_close(loop_.handle, req, fd, close_cb);
107107
return Ok(());
108108
}
109109

@@ -120,14 +120,14 @@ impl FsRequest {
120120
-> Result<(), UvError>
121121
{
122122
execute_nop(|req, cb| unsafe {
123-
uvll::uv_fs_mkdir(loop_.native_handle(), req, path.with_ref(|p| p),
123+
uvll::uv_fs_mkdir(loop_.handle, req, path.with_ref(|p| p),
124124
mode, cb)
125125
})
126126
}
127127

128128
pub fn rmdir(loop_: &Loop, path: &CString) -> Result<(), UvError> {
129129
execute_nop(|req, cb| unsafe {
130-
uvll::uv_fs_rmdir(loop_.native_handle(), req, path.with_ref(|p| p),
130+
uvll::uv_fs_rmdir(loop_.handle, req, path.with_ref(|p| p),
131131
cb)
132132
})
133133
}
@@ -136,7 +136,7 @@ impl FsRequest {
136136
-> Result<(), UvError>
137137
{
138138
execute_nop(|req, cb| unsafe {
139-
uvll::uv_fs_rename(loop_.native_handle(),
139+
uvll::uv_fs_rename(loop_.handle,
140140
req,
141141
path.with_ref(|p| p),
142142
to.with_ref(|p| p),
@@ -148,7 +148,7 @@ impl FsRequest {
148148
-> Result<(), UvError>
149149
{
150150
execute_nop(|req, cb| unsafe {
151-
uvll::uv_fs_chmod(loop_.native_handle(), req, path.with_ref(|p| p),
151+
uvll::uv_fs_chmod(loop_.handle, req, path.with_ref(|p| p),
152152
mode, cb)
153153
})
154154
}
@@ -157,7 +157,7 @@ impl FsRequest {
157157
-> Result<~[Path], UvError>
158158
{
159159
execute(|req, cb| unsafe {
160-
uvll::uv_fs_readdir(loop_.native_handle(),
160+
uvll::uv_fs_readdir(loop_.handle,
161161
req, path.with_ref(|p| p), flags, cb)
162162
}).map(|req| unsafe {
163163
let mut paths = ~[];
@@ -174,7 +174,7 @@ impl FsRequest {
174174

175175
pub fn readlink(loop_: &Loop, path: &CString) -> Result<Path, UvError> {
176176
do execute(|req, cb| unsafe {
177-
uvll::uv_fs_readlink(loop_.native_handle(), req,
177+
uvll::uv_fs_readlink(loop_.handle, req,
178178
path.with_ref(|p| p), cb)
179179
}).map |req| {
180180
Path::new(unsafe {
@@ -187,7 +187,7 @@ impl FsRequest {
187187
-> Result<(), UvError>
188188
{
189189
execute_nop(|req, cb| unsafe {
190-
uvll::uv_fs_chown(loop_.native_handle(),
190+
uvll::uv_fs_chown(loop_.handle,
191191
req, path.with_ref(|p| p),
192192
uid as uvll::uv_uid_t,
193193
gid as uvll::uv_gid_t,
@@ -199,15 +199,15 @@ impl FsRequest {
199199
-> Result<(), UvError>
200200
{
201201
execute_nop(|req, cb| unsafe {
202-
uvll::uv_fs_ftruncate(loop_.native_handle(), req, file, offset, cb)
202+
uvll::uv_fs_ftruncate(loop_.handle, req, file, offset, cb)
203203
})
204204
}
205205

206206
pub fn link(loop_: &Loop, src: &CString, dst: &CString)
207207
-> Result<(), UvError>
208208
{
209209
execute_nop(|req, cb| unsafe {
210-
uvll::uv_fs_link(loop_.native_handle(), req,
210+
uvll::uv_fs_link(loop_.handle, req,
211211
src.with_ref(|p| p),
212212
dst.with_ref(|p| p),
213213
cb)
@@ -218,7 +218,7 @@ impl FsRequest {
218218
-> Result<(), UvError>
219219
{
220220
execute_nop(|req, cb| unsafe {
221-
uvll::uv_fs_symlink(loop_.native_handle(), req,
221+
uvll::uv_fs_symlink(loop_.handle, req,
222222
src.with_ref(|p| p),
223223
dst.with_ref(|p| p),
224224
0, cb)
@@ -227,13 +227,13 @@ impl FsRequest {
227227

228228
pub fn fsync(loop_: &Loop, fd: c_int) -> Result<(), UvError> {
229229
execute_nop(|req, cb| unsafe {
230-
uvll::uv_fs_fsync(loop_.native_handle(), req, fd, cb)
230+
uvll::uv_fs_fsync(loop_.handle, req, fd, cb)
231231
})
232232
}
233233

234234
pub fn datasync(loop_: &Loop, fd: c_int) -> Result<(), UvError> {
235235
execute_nop(|req, cb| unsafe {
236-
uvll::uv_fs_fdatasync(loop_.native_handle(), req, fd, cb)
236+
uvll::uv_fs_fdatasync(loop_.handle, req, fd, cb)
237237
})
238238
}
239239

src/librustuv/idle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl IdleWatcher {
2626
pub fn new(loop_: &mut Loop) -> ~IdleWatcher {
2727
let handle = UvHandle::alloc(None::<IdleWatcher>, uvll::UV_IDLE);
2828
assert_eq!(unsafe {
29-
uvll::uv_idle_init(loop_.native_handle(), handle)
29+
uvll::uv_idle_init(loop_.handle, handle)
3030
}, 0);
3131
let me = ~IdleWatcher {
3232
handle: handle,
@@ -40,7 +40,7 @@ impl IdleWatcher {
4040
pub fn onetime(loop_: &mut Loop, f: proc()) {
4141
let handle = UvHandle::alloc(None::<IdleWatcher>, uvll::UV_IDLE);
4242
unsafe {
43-
assert_eq!(uvll::uv_idle_init(loop_.native_handle(), handle), 0);
43+
assert_eq!(uvll::uv_idle_init(loop_.handle, handle), 0);
4444
let data: *c_void = cast::transmute(~f);
4545
uvll::set_data_for_uv_handle(handle, data);
4646
assert_eq!(uvll::uv_idle_start(handle, onetime_cb), 0)

src/librustuv/lib.rs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ use std::rt::io::IoError;
5959

6060
//#[cfg(test)] use unstable::run_in_bare_thread;
6161

62+
pub use self::async::AsyncWatcher;
6263
pub use self::file::{FsRequest, FileWatcher};
63-
pub use self::net::{TcpWatcher, TcpListener, TcpAcceptor, UdpWatcher};
6464
pub use self::idle::IdleWatcher;
65-
pub use self::timer::TimerWatcher;
66-
pub use self::async::AsyncWatcher;
67-
pub use self::process::Process;
65+
pub use self::net::{TcpWatcher, TcpListener, TcpAcceptor, UdpWatcher};
6866
pub use self::pipe::{PipeWatcher, PipeListener, PipeAcceptor};
67+
pub use self::process::Process;
6968
pub use self::signal::SignalWatcher;
69+
pub use self::timer::TimerWatcher;
7070
pub use self::tty::TtyWatcher;
7171

7272
mod macros;
@@ -89,19 +89,6 @@ pub mod tty;
8989
pub mod signal;
9090
pub mod stream;
9191

92-
/// XXX: Loop(*handle) is buggy with destructors. Normal structs
93-
/// with dtors may not be destructured, but tuple structs can,
94-
/// but the results are not correct.
95-
pub struct Loop {
96-
priv handle: *uvll::uv_loop_t
97-
}
98-
99-
/// A type that wraps a native handle
100-
pub trait NativeHandle<T> {
101-
fn from_native_handle(T) -> Self;
102-
fn native_handle(&self) -> T;
103-
}
104-
10592
/// A type that wraps a uv handle
10693
pub trait UvHandle<T> {
10794
fn uv_handle(&self) -> *T;
@@ -185,28 +172,28 @@ impl Drop for Request {
185172
}
186173
}
187174

175+
/// XXX: Loop(*handle) is buggy with destructors. Normal structs
176+
/// with dtors may not be destructured, but tuple structs can,
177+
/// but the results are not correct.
178+
pub struct Loop {
179+
priv handle: *uvll::uv_loop_t
180+
}
181+
188182
impl Loop {
189183
pub fn new() -> Loop {
190184
let handle = unsafe { uvll::loop_new() };
191185
assert!(handle.is_not_null());
192-
NativeHandle::from_native_handle(handle)
186+
Loop::wrap(handle)
193187
}
194188

189+
pub fn wrap(handle: *uvll::uv_loop_t) -> Loop { Loop { handle: handle } }
190+
195191
pub fn run(&mut self) {
196-
unsafe { uvll::uv_run(self.native_handle(), uvll::RUN_DEFAULT) };
192+
unsafe { uvll::uv_run(self.handle, uvll::RUN_DEFAULT) };
197193
}
198194

199195
pub fn close(&mut self) {
200-
unsafe { uvll::uv_loop_delete(self.native_handle()) };
201-
}
202-
}
203-
204-
impl NativeHandle<*uvll::uv_loop_t> for Loop {
205-
fn from_native_handle(handle: *uvll::uv_loop_t) -> Loop {
206-
Loop { handle: handle }
207-
}
208-
fn native_handle(&self) -> *uvll::uv_loop_t {
209-
self.handle
196+
unsafe { uvll::uv_loop_delete(self.handle) };
210197
}
211198
}
212199

0 commit comments

Comments
 (0)