Fixing rebase conflicts and such

This cleans up the merging of removing ~fn() and removing C++ wrappers to a
compile-able and progress-ready state
This commit is contained in:
Alex Crichton 2013-11-04 14:03:32 -08:00
parent 18ce014e9d
commit 6690bcb101
9 changed files with 91 additions and 144 deletions

View File

@ -35,7 +35,7 @@ impl AsyncWatcher {
pub fn new(loop_: &mut Loop, cb: ~Callback) -> AsyncWatcher {
let handle = UvHandle::alloc(None::<AsyncWatcher>, uvll::UV_ASYNC);
assert_eq!(unsafe {
uvll::async_init(loop_.native_handle(), handle, async_cb)
uvll::uv_async_init(loop_.native_handle(), handle, async_cb)
}, 0);
let flag = Exclusive::new(false);
let payload = ~Payload { callback: cb, exit_flag: flag.clone() };
@ -49,7 +49,7 @@ impl AsyncWatcher {
impl UvHandle<uvll::uv_async_t> for AsyncWatcher {
fn uv_handle(&self) -> *uvll::uv_async_t { self.handle }
unsafe fn from_uv_handle<'a>(h: &'a *T) -> &'a mut AsyncWatcher {
unsafe fn from_uv_handle<'a>(_: &'a *uvll::uv_async_t) -> &'a mut AsyncWatcher {
fail!("async watchers can't be built from their handles");
}
}
@ -89,7 +89,7 @@ extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
payload.callback.call();
if should_exit {
unsafe { uvll::close(handle, close_cb) }
unsafe { uvll::uv_close(handle, close_cb) }
}
}
@ -104,7 +104,7 @@ extern fn close_cb(handle: *uvll::uv_handle_t) {
impl RemoteCallback for AsyncWatcher {
fn fire(&mut self) {
unsafe { uvll::async_send(self.handle) }
unsafe { uvll::uv_async_send(self.handle) }
}
}
@ -117,7 +117,7 @@ impl Drop for AsyncWatcher {
// signal and see the exit flag, destroying the handle
// before the final send.
*should_exit = true;
uvll::async_send(self.handle)
uvll::uv_async_send(self.handle)
}
}
}

View File

@ -13,7 +13,7 @@ use std::c_str;
use std::c_str::CString;
use std::cast::transmute;
use std::libc;
use std::libc::{c_int, c_char, c_void};
use std::libc::{c_int, c_char, c_void, c_uint};
use super::{Request, NativeHandle, Loop, FsCallback, Buf,
status_to_maybe_uv_error, UvError};
@ -147,25 +147,12 @@ impl FsRequest {
self.sync_cleanup(result)
}
<<<<<<< HEAD
pub fn close(mut self, loop_: &Loop, fd: c_int, cb: FsCallback) {
let complete_cb_ptr = self.req_boilerplate(Some(cb));
assert_eq!(unsafe {
uvll::fs_close(loop_.native_handle(), self.native_handle(),
fd, complete_cb_ptr)
}, 0);
=======
pub fn close(self, loop_: &Loop, fd: c_int, cb: FsCallback) {
let complete_cb_ptr = {
let mut me = self;
me.req_boilerplate(Some(cb))
};
let ret = unsafe {
uvll::uv_fs_close(loop_.native_handle(), self.native_handle(),
fd, complete_cb_ptr)
};
assert_eq!(ret, 0);
>>>>>>> 1850d26... Remove lots of uv/C++ wrappers
}, 0);
}
pub fn close_sync(mut self, loop_: &Loop,
fd: c_int) -> Result<c_int, UvError> {
@ -177,21 +164,20 @@ impl FsRequest {
self.sync_cleanup(result)
}
<<<<<<< HEAD
pub fn mkdir(mut self, loop_: &Loop, path: &CString, mode: c_int,
cb: FsCallback) {
let complete_cb_ptr = self.req_boilerplate(Some(cb));
assert_eq!(path.with_ref(|p| unsafe {
uvll::fs_mkdir(loop_.native_handle(),
self.native_handle(), p, mode, complete_cb_ptr)
uvll::uv_fs_mkdir(loop_.native_handle(),
self.native_handle(), p, mode, complete_cb_ptr)
}), 0);
}
pub fn rmdir(mut self, loop_: &Loop, path: &CString, cb: FsCallback) {
let complete_cb_ptr = self.req_boilerplate(Some(cb));
assert_eq!(path.with_ref(|p| unsafe {
uvll::fs_rmdir(loop_.native_handle(),
self.native_handle(), p, complete_cb_ptr)
uvll::uv_fs_rmdir(loop_.native_handle(),
self.native_handle(), p, complete_cb_ptr)
}), 0);
}
@ -199,11 +185,11 @@ impl FsRequest {
cb: FsCallback) {
let complete_cb_ptr = self.req_boilerplate(Some(cb));
assert_eq!(unsafe {
uvll::fs_rename(loop_.native_handle(),
self.native_handle(),
path.with_ref(|p| p),
to.with_ref(|p| p),
complete_cb_ptr)
uvll::uv_fs_rename(loop_.native_handle(),
self.native_handle(),
path.with_ref(|p| p),
to.with_ref(|p| p),
complete_cb_ptr)
}, 0);
}
@ -211,43 +197,17 @@ impl FsRequest {
cb: FsCallback) {
let complete_cb_ptr = self.req_boilerplate(Some(cb));
assert_eq!(path.with_ref(|p| unsafe {
uvll::fs_chmod(loop_.native_handle(), self.native_handle(), p, mode,
complete_cb_ptr)
uvll::uv_fs_chmod(loop_.native_handle(), self.native_handle(), p,
mode, complete_cb_ptr)
}), 0);
=======
pub fn mkdir(self, loop_: &Loop, path: &CString, mode: int, cb: FsCallback) {
let complete_cb_ptr = {
let mut me = self;
me.req_boilerplate(Some(cb))
};
let ret = path.with_ref(|p| unsafe {
uvll::uv_fs_mkdir(loop_.native_handle(),
self.native_handle(), p,
mode as c_int, complete_cb_ptr)
});
assert_eq!(ret, 0);
}
pub fn rmdir(self, loop_: &Loop, path: &CString, cb: FsCallback) {
let complete_cb_ptr = {
let mut me = self;
me.req_boilerplate(Some(cb))
};
let ret = path.with_ref(|p| unsafe {
uvll::uv_fs_rmdir(loop_.native_handle(),
self.native_handle(), p, complete_cb_ptr)
});
assert_eq!(ret, 0);
>>>>>>> 1850d26... Remove lots of uv/C++ wrappers
}
pub fn readdir(mut self, loop_: &Loop, path: &CString,
flags: c_int, cb: FsCallback) {
<<<<<<< HEAD
let complete_cb_ptr = self.req_boilerplate(Some(cb));
assert_eq!(path.with_ref(|p| unsafe {
uvll::fs_readdir(loop_.native_handle(),
self.native_handle(), p, flags, complete_cb_ptr)
uvll::uv_fs_readdir(loop_.native_handle(),
self.native_handle(), p, flags, complete_cb_ptr)
}), 0);
}
@ -318,17 +278,6 @@ impl FsRequest {
uvll::uv_fs_fdatasync(loop_.native_handle(), self.native_handle(), fd,
complete_cb_ptr)
}, 0);
=======
let complete_cb_ptr = {
let mut me = self;
me.req_boilerplate(Some(cb))
};
let ret = path.with_ref(|p| unsafe {
uvll::uv_fs_readdir(loop_.native_handle(),
self.native_handle(), p, flags, complete_cb_ptr)
});
assert_eq!(ret, 0);
>>>>>>> 1850d26... Remove lots of uv/C++ wrappers
}
// accessors/utility funcs

View File

@ -26,7 +26,7 @@ impl IdleWatcher {
pub fn new(loop_: &mut Loop) -> ~IdleWatcher {
let handle = UvHandle::alloc(None::<IdleWatcher>, uvll::UV_IDLE);
assert_eq!(unsafe {
uvll::idle_init(loop_.native_handle(), handle)
uvll::uv_idle_init(loop_.native_handle(), handle)
}, 0);
let me = ~IdleWatcher {
handle: handle,
@ -40,10 +40,10 @@ impl IdleWatcher {
pub fn onetime(loop_: &mut Loop, f: proc()) {
let handle = UvHandle::alloc(None::<IdleWatcher>, uvll::UV_IDLE);
unsafe {
assert_eq!(uvll::idle_init(loop_.native_handle(), handle), 0);
assert_eq!(uvll::uv_idle_init(loop_.native_handle(), handle), 0);
let data: *c_void = cast::transmute(~f);
uvll::set_data_for_uv_handle(handle, data);
assert_eq!(uvll::idle_start(handle, onetime_cb), 0)
assert_eq!(uvll::uv_idle_start(handle, onetime_cb), 0)
}
extern fn onetime_cb(handle: *uvll::uv_idle_t, status: c_int) {
@ -52,8 +52,8 @@ impl IdleWatcher {
let data = uvll::get_data_for_uv_handle(handle);
let f: ~proc() = cast::transmute(data);
(*f)();
uvll::idle_stop(handle);
uvll::close(handle, close_cb);
uvll::uv_idle_stop(handle);
uvll::uv_close(handle, close_cb);
}
}
@ -67,18 +67,18 @@ impl PausibleIdleCallback for IdleWatcher {
fn start(&mut self, cb: ~Callback) {
assert!(self.callback.is_none());
self.callback = Some(cb);
assert_eq!(unsafe { uvll::idle_start(self.handle, idle_cb) }, 0)
assert_eq!(unsafe { uvll::uv_idle_start(self.handle, idle_cb) }, 0)
self.idle_flag = true;
}
fn pause(&mut self) {
if self.idle_flag == true {
assert_eq!(unsafe {uvll::idle_stop(self.handle) }, 0);
assert_eq!(unsafe {uvll::uv_idle_stop(self.handle) }, 0);
self.idle_flag = false;
}
}
fn resume(&mut self) {
if self.idle_flag == false {
assert_eq!(unsafe { uvll::idle_start(self.handle, idle_cb) }, 0)
assert_eq!(unsafe { uvll::uv_idle_start(self.handle, idle_cb) }, 0)
self.idle_flag = true;
}
}

View File

@ -50,7 +50,7 @@ use std::str::raw::from_c_str;
use std::vec;
use std::ptr;
use std::str;
use std::libc::{c_void, c_int, size_t, malloc, free, c_char, c_uint};
use std::libc::{c_void, c_int, size_t, malloc, free};
use std::cast::transmute;
use std::ptr::null;
use std::unstable::finally::Finally;
@ -153,7 +153,7 @@ pub trait UvHandle<T> {
unsafe {
uvll::set_data_for_uv_handle(self.uv_handle(), null::<()>());
uvll::close(self.uv_handle(), close_cb)
uvll::uv_close(self.uv_handle() as *uvll::uv_handle_t, close_cb)
}
}
}

View File

@ -201,32 +201,30 @@ impl RtioProcess for Process {
}
fn kill(&mut self, signal: int) -> Result<(), IoError> {
do self.home_for_io |self_| {
match unsafe {
uvll::process_kill(self_.handle, signal as libc::c_int)
} {
0 => Ok(()),
err => Err(uv_error_to_io_error(UvError(err)))
}
let _m = self.fire_missiles();
match unsafe {
uvll::uv_process_kill(self.handle, signal as libc::c_int)
} {
0 => Ok(()),
err => Err(uv_error_to_io_error(UvError(err)))
}
}
fn wait(&mut self) -> int {
// Make sure (on the home scheduler) that we have an exit status listed
do self.home_for_io |self_| {
match self_.exit_status {
Some(*) => {}
None => {
// If there's no exit code previously listed, then the
// process's exit callback has yet to be invoked. We just
// need to deschedule ourselves and wait to be reawoken.
let scheduler: ~Scheduler = Local::take();
do scheduler.deschedule_running_task_and_then |_, task| {
assert!(self_.to_wake.is_none());
self_.to_wake = Some(task);
}
assert!(self_.exit_status.is_some());
let _m = self.fire_missiles();
match self.exit_status {
Some(*) => {}
None => {
// If there's no exit code previously listed, then the
// process's exit callback has yet to be invoked. We just
// need to deschedule ourselves and wait to be reawoken.
let scheduler: ~Scheduler = Local::take();
do scheduler.deschedule_running_task_and_then |_, task| {
assert!(self.to_wake.is_none());
self.to_wake = Some(task);
}
assert!(self.exit_status.is_some());
}
}
@ -237,9 +235,8 @@ impl RtioProcess for Process {
impl Drop for Process {
fn drop(&mut self) {
do self.home_for_io |self_| {
assert!(self_.to_wake.is_none());
self_.close_async_();
}
let _m = self.fire_missiles();
assert!(self.to_wake.is_none());
self.close_async_();
}
}

View File

@ -32,10 +32,10 @@ impl SignalWatcher {
channel: SharedChan<Signum>) -> Result<~SignalWatcher, UvError> {
let handle = UvHandle::alloc(None::<SignalWatcher>, uvll::UV_SIGNAL);
assert_eq!(unsafe {
uvll::signal_init(loop_.native_handle(), handle)
uvll::uv_signal_init(loop_.native_handle(), handle)
}, 0);
match unsafe { uvll::signal_start(handle, signal_cb, signum as c_int) } {
match unsafe { uvll::uv_signal_start(handle, signal_cb, signum as c_int) } {
0 => {
let s = ~SignalWatcher {
handle: handle,
@ -72,8 +72,7 @@ impl RtioSignal for SignalWatcher {}
impl Drop for SignalWatcher {
fn drop(&mut self) {
do self.home_for_io |self_| {
self_.close_async_();
}
let _m = self.fire_missiles();
self.close_async_();
}
}

View File

@ -36,7 +36,7 @@ impl TimerWatcher {
pub fn new(loop_: &mut Loop) -> ~TimerWatcher {
let handle = UvHandle::alloc(None::<TimerWatcher>, uvll::UV_TIMER);
assert_eq!(unsafe {
uvll::timer_init(loop_.native_handle(), handle)
uvll::uv_timer_init(loop_.native_handle(), handle)
}, 0);
let me = ~TimerWatcher {
handle: handle,
@ -48,12 +48,12 @@ impl TimerWatcher {
fn start(&mut self, msecs: u64, period: u64) {
assert_eq!(unsafe {
uvll::timer_start(self.handle, timer_cb, msecs, period)
uvll::uv_timer_start(self.handle, timer_cb, msecs, period)
}, 0)
}
fn stop(&mut self) {
assert_eq!(unsafe { uvll::timer_stop(self.handle) }, 0)
assert_eq!(unsafe { uvll::uv_timer_stop(self.handle) }, 0)
}
}
@ -67,23 +67,21 @@ impl UvHandle<uvll::uv_timer_t> for TimerWatcher {
impl RtioTimer for TimerWatcher {
fn sleep(&mut self, msecs: u64) {
do self.home_for_io_with_sched |self_, scheduler| {
do scheduler.deschedule_running_task_and_then |_sched, task| {
self_.action = Some(WakeTask(task));
self_.start(msecs, 0);
}
self_.stop();
let (_m, sched) = self.fire_missiles_sched();
do sched.deschedule_running_task_and_then |_sched, task| {
self.action = Some(WakeTask(task));
self.start(msecs, 0);
}
self.stop();
}
fn oneshot(&mut self, msecs: u64) -> PortOne<()> {
let (port, chan) = oneshot();
let chan = Cell::new(chan);
do self.home_for_io |self_| {
self_.action = Some(SendOnce(chan.take()));
self_.start(msecs, 0);
}
let _m = self.fire_missiles();
self.action = Some(SendOnce(chan.take()));
self.start(msecs, 0);
return port;
}
@ -92,10 +90,9 @@ impl RtioTimer for TimerWatcher {
let (port, chan) = stream();
let chan = Cell::new(chan);
do self.home_for_io |self_| {
self_.action = Some(SendMany(chan.take()));
self_.start(msecs, msecs);
}
let _m = self.fire_missiles();
self.action = Some(SendMany(chan.take()));
self.start(msecs, msecs);
return port;
}
@ -119,11 +116,10 @@ extern fn timer_cb(handle: *uvll::uv_timer_t, _status: c_int) {
impl Drop for TimerWatcher {
fn drop(&mut self) {
do self.home_for_io |self_| {
self_.action = None;
self_.stop();
self_.close_async_();
}
let _m = self.fire_missiles();
self.action = None;
self.stop();
self.close_async_();
}
}

View File

@ -14,6 +14,7 @@ use std::cast;
use std::cell::Cell;
use std::clone::Clone;
use std::comm::{SharedChan, GenericChan};
use std::libc;
use std::libc::{c_int, c_uint, c_void};
use std::ptr;
use std::str;
@ -30,9 +31,9 @@ use std::rt::tube::Tube;
use std::rt::task::Task;
use std::path::{GenericPath, Path};
use std::libc::{lseek, off_t, O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY,
O_WRONLY, S_IRUSR, S_IWUSR, S_IRWXU};
use std::rt::io::{FileMode, FileAccess, OpenOrCreate, Open, Create,
CreateOrTruncate, Append, Truncate, Read, Write, ReadWrite,
O_WRONLY, S_IRUSR, S_IWUSR};
use std::rt::io::{FileMode, FileAccess, Open,
Append, Truncate, Read, Write, ReadWrite,
FileStat};
use std::rt::io::signal::Signum;
use std::task;
@ -1224,7 +1225,7 @@ impl UvFileStream {
do sched.deschedule_running_task_and_then |_, task| {
let task = Cell::new(task);
let req = file::FsRequest::new();
do f(self_, req) |_, uverr| {
do f(self, req) |_, uverr| {
let res = match uverr {
None => Ok(()),
Some(err) => Err(uv_error_to_io_error(err))

View File

@ -724,6 +724,7 @@ extern {
fn rust_set_stdio_container_fd(c: *uv_stdio_container_t, fd: c_int);
fn rust_set_stdio_container_stream(c: *uv_stdio_container_t,
stream: *uv_stream_t);
fn rust_uv_process_pid(p: *uv_process_t) -> c_int;
}
// generic uv functions
@ -809,21 +810,25 @@ externfn!(fn uv_fs_readdir(l: *uv_loop_t, req: *uv_fs_t, path: *c_char,
flags: c_int, cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_req_cleanup(req: *uv_fs_t))
externfn!(fn uv_fs_fsync(handle: *uv_loop_t, req: *uv_fs_t, file: c_int,
cb: *u8) -> c_int)
cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_fdatasync(handle: *uv_loop_t, req: *uv_fs_t, file: c_int,
cb: *u8) -> c_int)
cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_ftruncate(handle: *uv_loop_t, req: *uv_fs_t, file: c_int,
offset: i64, cb: *u8) -> c_int)
offset: i64, cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_readlink(handle: *uv_loop_t, req: *uv_fs_t, file: *c_char,
cb: *u8) -> c_int)
cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_symlink(handle: *uv_loop_t, req: *uv_fs_t, src: *c_char,
dst: *c_char, flags: c_int, cb: *u8) -> c_int)
dst: *c_char, flags: c_int, cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_rename(handle: *uv_loop_t, req: *uv_fs_t, src: *c_char,
dst: *c_char, cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_link(handle: *uv_loop_t, req: *uv_fs_t, src: *c_char,
dst: *c_char, cb: *u8) -> c_int)
dst: *c_char, cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_chown(handle: *uv_loop_t, req: *uv_fs_t, src: *c_char,
uid: uv_uid_t, gid: uv_gid_t, cb: *u8) -> c_int)
uid: uv_uid_t, gid: uv_gid_t, cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_chmod(handle: *uv_loop_t, req: *uv_fs_t, path: *c_char,
mode: c_int, cb: uv_fs_cb) -> c_int)
externfn!(fn uv_fs_lstat(handle: *uv_loop_t, req: *uv_fs_t, file: *c_char,
cb: *u8) -> c_int)
cb: uv_fs_cb) -> c_int)
// getaddrinfo
externfn!(fn uv_getaddrinfo(loop_: *uv_loop_t, req: *uv_getaddrinfo_t,