Clean up the remaining chunks of uv
This commit is contained in:
parent
584b359348
commit
aa78c3d6f6
@ -17,7 +17,7 @@
|
||||
use std::rt::sched::Scheduler;
|
||||
|
||||
use net;
|
||||
use super::{Loop, UvError, NativeHandle, Request};
|
||||
use super::{Loop, UvError, Request};
|
||||
use uvll;
|
||||
|
||||
struct Addrinfo {
|
||||
@ -79,7 +79,7 @@ pub fn run(loop_: &Loop, node: Option<&str>, service: Option<&str>,
|
||||
let req = Request::new(uvll::UV_GETADDRINFO);
|
||||
|
||||
return match unsafe {
|
||||
uvll::uv_getaddrinfo(loop_.native_handle(), req.handle,
|
||||
uvll::uv_getaddrinfo(loop_.handle, req.handle,
|
||||
getaddrinfo_cb, c_node_ptr, c_service_ptr,
|
||||
hint_ptr)
|
||||
} {
|
||||
|
@ -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::uv_async_init(loop_.native_handle(), handle, async_cb)
|
||||
uvll::uv_async_init(loop_.handle, handle, async_cb)
|
||||
}, 0);
|
||||
let flag = Exclusive::new(false);
|
||||
let payload = ~Payload { callback: cb, exit_flag: flag.clone() };
|
||||
|
@ -22,7 +22,7 @@
|
||||
use std::rt::sched::{Scheduler, SchedHandle};
|
||||
use std::vec;
|
||||
|
||||
use super::{NativeHandle, Loop, UvError, uv_error_to_io_error};
|
||||
use super::{Loop, UvError, uv_error_to_io_error};
|
||||
use uvio::HomingIO;
|
||||
use uvll;
|
||||
|
||||
@ -43,7 +43,7 @@ pub fn open(loop_: &Loop, path: &CString, flags: int, mode: int)
|
||||
-> Result<FileWatcher, UvError>
|
||||
{
|
||||
execute(|req, cb| unsafe {
|
||||
uvll::uv_fs_open(loop_.native_handle(),
|
||||
uvll::uv_fs_open(loop_.handle,
|
||||
req, path.with_ref(|p| p), flags as c_int,
|
||||
mode as c_int, cb)
|
||||
}).map(|req|
|
||||
@ -54,21 +54,21 @@ pub fn open(loop_: &Loop, path: &CString, flags: int, mode: int)
|
||||
|
||||
pub fn unlink(loop_: &Loop, path: &CString) -> Result<(), UvError> {
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_unlink(loop_.native_handle(), req, path.with_ref(|p| p),
|
||||
uvll::uv_fs_unlink(loop_.handle, req, path.with_ref(|p| p),
|
||||
cb)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn lstat(loop_: &Loop, path: &CString) -> Result<FileStat, UvError> {
|
||||
execute(|req, cb| unsafe {
|
||||
uvll::uv_fs_lstat(loop_.native_handle(), req, path.with_ref(|p| p),
|
||||
uvll::uv_fs_lstat(loop_.handle, req, path.with_ref(|p| p),
|
||||
cb)
|
||||
}).map(|req| req.mkstat())
|
||||
}
|
||||
|
||||
pub fn stat(loop_: &Loop, path: &CString) -> Result<FileStat, UvError> {
|
||||
execute(|req, cb| unsafe {
|
||||
uvll::uv_fs_stat(loop_.native_handle(), req, path.with_ref(|p| p),
|
||||
uvll::uv_fs_stat(loop_.handle, req, path.with_ref(|p| p),
|
||||
cb)
|
||||
}).map(|req| req.mkstat())
|
||||
}
|
||||
@ -77,7 +77,7 @@ pub fn write(loop_: &Loop, fd: c_int, buf: &[u8], offset: i64)
|
||||
-> Result<(), UvError>
|
||||
{
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_write(loop_.native_handle(), req,
|
||||
uvll::uv_fs_write(loop_.handle, req,
|
||||
fd, vec::raw::to_ptr(buf) as *c_void,
|
||||
buf.len() as c_uint, offset, cb)
|
||||
})
|
||||
@ -87,7 +87,7 @@ pub fn read(loop_: &Loop, fd: c_int, buf: &mut [u8], offset: i64)
|
||||
-> Result<int, UvError>
|
||||
{
|
||||
do execute(|req, cb| unsafe {
|
||||
uvll::uv_fs_read(loop_.native_handle(), req,
|
||||
uvll::uv_fs_read(loop_.handle, req,
|
||||
fd, vec::raw::to_ptr(buf) as *c_void,
|
||||
buf.len() as c_uint, offset, cb)
|
||||
}).map |req| {
|
||||
@ -98,12 +98,12 @@ pub fn read(loop_: &Loop, fd: c_int, buf: &mut [u8], offset: i64)
|
||||
pub fn close(loop_: &Loop, fd: c_int, sync: bool) -> Result<(), UvError> {
|
||||
if sync {
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_close(loop_.native_handle(), req, fd, cb)
|
||||
uvll::uv_fs_close(loop_.handle, req, fd, cb)
|
||||
})
|
||||
} else {
|
||||
unsafe {
|
||||
let req = uvll::malloc_req(uvll::UV_FS);
|
||||
uvll::uv_fs_close(loop_.native_handle(), req, fd, close_cb);
|
||||
uvll::uv_fs_close(loop_.handle, req, fd, close_cb);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -120,14 +120,14 @@ pub fn mkdir(loop_: &Loop, path: &CString, mode: c_int)
|
||||
-> Result<(), UvError>
|
||||
{
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_mkdir(loop_.native_handle(), req, path.with_ref(|p| p),
|
||||
uvll::uv_fs_mkdir(loop_.handle, req, path.with_ref(|p| p),
|
||||
mode, cb)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn rmdir(loop_: &Loop, path: &CString) -> Result<(), UvError> {
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_rmdir(loop_.native_handle(), req, path.with_ref(|p| p),
|
||||
uvll::uv_fs_rmdir(loop_.handle, req, path.with_ref(|p| p),
|
||||
cb)
|
||||
})
|
||||
}
|
||||
@ -136,7 +136,7 @@ pub fn rename(loop_: &Loop, path: &CString, to: &CString)
|
||||
-> Result<(), UvError>
|
||||
{
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_rename(loop_.native_handle(),
|
||||
uvll::uv_fs_rename(loop_.handle,
|
||||
req,
|
||||
path.with_ref(|p| p),
|
||||
to.with_ref(|p| p),
|
||||
@ -148,7 +148,7 @@ pub fn chmod(loop_: &Loop, path: &CString, mode: c_int)
|
||||
-> Result<(), UvError>
|
||||
{
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_chmod(loop_.native_handle(), req, path.with_ref(|p| p),
|
||||
uvll::uv_fs_chmod(loop_.handle, req, path.with_ref(|p| p),
|
||||
mode, cb)
|
||||
})
|
||||
}
|
||||
@ -157,7 +157,7 @@ pub fn readdir(loop_: &Loop, path: &CString, flags: c_int)
|
||||
-> Result<~[Path], UvError>
|
||||
{
|
||||
execute(|req, cb| unsafe {
|
||||
uvll::uv_fs_readdir(loop_.native_handle(),
|
||||
uvll::uv_fs_readdir(loop_.handle,
|
||||
req, path.with_ref(|p| p), flags, cb)
|
||||
}).map(|req| unsafe {
|
||||
let mut paths = ~[];
|
||||
@ -174,7 +174,7 @@ pub fn readdir(loop_: &Loop, path: &CString, flags: c_int)
|
||||
|
||||
pub fn readlink(loop_: &Loop, path: &CString) -> Result<Path, UvError> {
|
||||
do execute(|req, cb| unsafe {
|
||||
uvll::uv_fs_readlink(loop_.native_handle(), req,
|
||||
uvll::uv_fs_readlink(loop_.handle, req,
|
||||
path.with_ref(|p| p), cb)
|
||||
}).map |req| {
|
||||
Path::new(unsafe {
|
||||
@ -187,7 +187,7 @@ pub fn chown(loop_: &Loop, path: &CString, uid: int, gid: int)
|
||||
-> Result<(), UvError>
|
||||
{
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_chown(loop_.native_handle(),
|
||||
uvll::uv_fs_chown(loop_.handle,
|
||||
req, path.with_ref(|p| p),
|
||||
uid as uvll::uv_uid_t,
|
||||
gid as uvll::uv_gid_t,
|
||||
@ -199,7 +199,7 @@ pub fn truncate(loop_: &Loop, file: c_int, offset: i64)
|
||||
-> Result<(), UvError>
|
||||
{
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_ftruncate(loop_.native_handle(), req, file, offset, cb)
|
||||
uvll::uv_fs_ftruncate(loop_.handle, req, file, offset, cb)
|
||||
})
|
||||
}
|
||||
|
||||
@ -207,7 +207,7 @@ pub fn link(loop_: &Loop, src: &CString, dst: &CString)
|
||||
-> Result<(), UvError>
|
||||
{
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_link(loop_.native_handle(), req,
|
||||
uvll::uv_fs_link(loop_.handle, req,
|
||||
src.with_ref(|p| p),
|
||||
dst.with_ref(|p| p),
|
||||
cb)
|
||||
@ -218,7 +218,7 @@ pub fn symlink(loop_: &Loop, src: &CString, dst: &CString)
|
||||
-> Result<(), UvError>
|
||||
{
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_symlink(loop_.native_handle(), req,
|
||||
uvll::uv_fs_symlink(loop_.handle, req,
|
||||
src.with_ref(|p| p),
|
||||
dst.with_ref(|p| p),
|
||||
0, cb)
|
||||
@ -227,13 +227,13 @@ pub fn symlink(loop_: &Loop, src: &CString, dst: &CString)
|
||||
|
||||
pub fn fsync(loop_: &Loop, fd: c_int) -> Result<(), UvError> {
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_fsync(loop_.native_handle(), req, fd, cb)
|
||||
uvll::uv_fs_fsync(loop_.handle, req, fd, cb)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn datasync(loop_: &Loop, fd: c_int) -> Result<(), UvError> {
|
||||
execute_nop(|req, cb| unsafe {
|
||||
uvll::uv_fs_fdatasync(loop_.native_handle(), req, fd, cb)
|
||||
uvll::uv_fs_fdatasync(loop_.handle, req, fd, cb)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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::uv_idle_init(loop_.native_handle(), handle)
|
||||
uvll::uv_idle_init(loop_.handle, handle)
|
||||
}, 0);
|
||||
let me = ~IdleWatcher {
|
||||
handle: handle,
|
||||
@ -40,7 +40,7 @@ pub fn new(loop_: &mut Loop) -> ~IdleWatcher {
|
||||
pub fn onetime(loop_: &mut Loop, f: proc()) {
|
||||
let handle = UvHandle::alloc(None::<IdleWatcher>, uvll::UV_IDLE);
|
||||
unsafe {
|
||||
assert_eq!(uvll::uv_idle_init(loop_.native_handle(), handle), 0);
|
||||
assert_eq!(uvll::uv_idle_init(loop_.handle, handle), 0);
|
||||
let data: *c_void = cast::transmute(~f);
|
||||
uvll::set_data_for_uv_handle(handle, data);
|
||||
assert_eq!(uvll::uv_idle_start(handle, onetime_cb), 0)
|
||||
|
@ -59,14 +59,14 @@
|
||||
|
||||
//#[cfg(test)] use unstable::run_in_bare_thread;
|
||||
|
||||
pub use self::file::{FsRequest, FileWatcher};
|
||||
pub use self::net::{TcpWatcher, TcpListener, TcpAcceptor, UdpWatcher};
|
||||
pub use self::idle::IdleWatcher;
|
||||
pub use self::timer::TimerWatcher;
|
||||
pub use self::async::AsyncWatcher;
|
||||
pub use self::process::Process;
|
||||
pub use self::file::{FsRequest, FileWatcher};
|
||||
pub use self::idle::IdleWatcher;
|
||||
pub use self::net::{TcpWatcher, TcpListener, TcpAcceptor, UdpWatcher};
|
||||
pub use self::pipe::{PipeWatcher, PipeListener, PipeAcceptor};
|
||||
pub use self::process::Process;
|
||||
pub use self::signal::SignalWatcher;
|
||||
pub use self::timer::TimerWatcher;
|
||||
pub use self::tty::TtyWatcher;
|
||||
|
||||
mod macros;
|
||||
@ -89,19 +89,6 @@
|
||||
pub mod signal;
|
||||
pub mod stream;
|
||||
|
||||
/// XXX: Loop(*handle) is buggy with destructors. Normal structs
|
||||
/// with dtors may not be destructured, but tuple structs can,
|
||||
/// but the results are not correct.
|
||||
pub struct Loop {
|
||||
priv handle: *uvll::uv_loop_t
|
||||
}
|
||||
|
||||
/// A type that wraps a native handle
|
||||
pub trait NativeHandle<T> {
|
||||
fn from_native_handle(T) -> Self;
|
||||
fn native_handle(&self) -> T;
|
||||
}
|
||||
|
||||
/// A type that wraps a uv handle
|
||||
pub trait UvHandle<T> {
|
||||
fn uv_handle(&self) -> *T;
|
||||
@ -185,28 +172,28 @@ fn drop(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
/// XXX: Loop(*handle) is buggy with destructors. Normal structs
|
||||
/// with dtors may not be destructured, but tuple structs can,
|
||||
/// but the results are not correct.
|
||||
pub struct Loop {
|
||||
priv handle: *uvll::uv_loop_t
|
||||
}
|
||||
|
||||
impl Loop {
|
||||
pub fn new() -> Loop {
|
||||
let handle = unsafe { uvll::loop_new() };
|
||||
assert!(handle.is_not_null());
|
||||
NativeHandle::from_native_handle(handle)
|
||||
Loop::wrap(handle)
|
||||
}
|
||||
|
||||
pub fn wrap(handle: *uvll::uv_loop_t) -> Loop { Loop { handle: handle } }
|
||||
|
||||
pub fn run(&mut self) {
|
||||
unsafe { uvll::uv_run(self.native_handle(), uvll::RUN_DEFAULT) };
|
||||
unsafe { uvll::uv_run(self.handle, uvll::RUN_DEFAULT) };
|
||||
}
|
||||
|
||||
pub fn close(&mut self) {
|
||||
unsafe { uvll::uv_loop_delete(self.native_handle()) };
|
||||
}
|
||||
}
|
||||
|
||||
impl NativeHandle<*uvll::uv_loop_t> for Loop {
|
||||
fn from_native_handle(handle: *uvll::uv_loop_t) -> Loop {
|
||||
Loop { handle: handle }
|
||||
}
|
||||
fn native_handle(&self) -> *uvll::uv_loop_t {
|
||||
self.handle
|
||||
unsafe { uvll::uv_loop_delete(self.handle) };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,40 +13,38 @@
|
||||
use std::ptr;
|
||||
use std::rt::BlockedTask;
|
||||
use std::rt::io::IoError;
|
||||
use std::rt::io::net::ip::{Ipv4Addr, Ipv6Addr};
|
||||
use std::rt::io::net::ip::{Ipv4Addr, Ipv6Addr, SocketAddr, IpAddr};
|
||||
use std::rt::local::Local;
|
||||
use std::rt::io::net::ip::{SocketAddr, IpAddr};
|
||||
use std::rt::rtio;
|
||||
use std::rt::sched::{Scheduler, SchedHandle};
|
||||
use std::rt::tube::Tube;
|
||||
use std::str;
|
||||
use std::vec;
|
||||
|
||||
use uvll;
|
||||
use uvll::*;
|
||||
use super::{
|
||||
Loop, Request, UvError, Buf, NativeHandle,
|
||||
status_to_io_result,
|
||||
use stream::StreamWatcher;
|
||||
use super::{Loop, Request, UvError, Buf, status_to_io_result,
|
||||
uv_error_to_io_error, UvHandle, slice_to_uv_buf};
|
||||
use uvio::HomingIO;
|
||||
use stream::StreamWatcher;
|
||||
use uvll;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Generic functions related to dealing with sockaddr things
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub enum UvSocketAddr {
|
||||
UvIpv4SocketAddr(*sockaddr_in),
|
||||
UvIpv6SocketAddr(*sockaddr_in6),
|
||||
UvIpv4SocketAddr(*uvll::sockaddr_in),
|
||||
UvIpv6SocketAddr(*uvll::sockaddr_in6),
|
||||
}
|
||||
|
||||
pub fn sockaddr_to_UvSocketAddr(addr: *uvll::sockaddr) -> UvSocketAddr {
|
||||
unsafe {
|
||||
assert!((is_ip4_addr(addr) || is_ip6_addr(addr)));
|
||||
assert!(!(is_ip4_addr(addr) && is_ip6_addr(addr)));
|
||||
assert!((uvll::is_ip4_addr(addr) || uvll::is_ip6_addr(addr)));
|
||||
assert!(!(uvll::is_ip4_addr(addr) && uvll::is_ip6_addr(addr)));
|
||||
match addr {
|
||||
_ if is_ip4_addr(addr) => UvIpv4SocketAddr(addr as *uvll::sockaddr_in),
|
||||
_ if is_ip6_addr(addr) => UvIpv6SocketAddr(addr as *uvll::sockaddr_in6),
|
||||
_ if uvll::is_ip4_addr(addr) =>
|
||||
UvIpv4SocketAddr(addr as *uvll::sockaddr_in),
|
||||
_ if uvll::is_ip6_addr(addr) =>
|
||||
UvIpv6SocketAddr(addr as *uvll::sockaddr_in6),
|
||||
_ => fail!(),
|
||||
}
|
||||
}
|
||||
@ -54,16 +52,16 @@ pub fn sockaddr_to_UvSocketAddr(addr: *uvll::sockaddr) -> UvSocketAddr {
|
||||
|
||||
fn socket_addr_as_uv_socket_addr<T>(addr: SocketAddr, f: &fn(UvSocketAddr) -> T) -> T {
|
||||
let malloc = match addr.ip {
|
||||
Ipv4Addr(*) => malloc_ip4_addr,
|
||||
Ipv6Addr(*) => malloc_ip6_addr,
|
||||
Ipv4Addr(*) => uvll::malloc_ip4_addr,
|
||||
Ipv6Addr(*) => uvll::malloc_ip6_addr,
|
||||
};
|
||||
let wrap = match addr.ip {
|
||||
Ipv4Addr(*) => UvIpv4SocketAddr,
|
||||
Ipv6Addr(*) => UvIpv6SocketAddr,
|
||||
};
|
||||
let free = match addr.ip {
|
||||
Ipv4Addr(*) => free_ip4_addr,
|
||||
Ipv6Addr(*) => free_ip6_addr,
|
||||
Ipv4Addr(*) => uvll::free_ip4_addr,
|
||||
Ipv6Addr(*) => uvll::free_ip6_addr,
|
||||
};
|
||||
|
||||
let addr = unsafe { malloc(addr.ip.to_str(), addr.port as int) };
|
||||
@ -194,7 +192,7 @@ impl TcpWatcher {
|
||||
pub fn new(loop_: &Loop) -> TcpWatcher {
|
||||
let handle = unsafe { uvll::malloc_handle(uvll::UV_TCP) };
|
||||
assert_eq!(unsafe {
|
||||
uvll::uv_tcp_init(loop_.native_handle(), handle)
|
||||
uvll::uv_tcp_init(loop_.handle, handle)
|
||||
}, 0);
|
||||
TcpWatcher {
|
||||
home: get_handle_to_current_scheduler!(),
|
||||
@ -223,8 +221,9 @@ struct Ctx { status: c_int, task: Option<BlockedTask> }
|
||||
};
|
||||
match result {
|
||||
0 => {
|
||||
req.defuse();
|
||||
let mut cx = Ctx { status: 0, task: None };
|
||||
req.set_data(&cx);
|
||||
req.defuse();
|
||||
let scheduler: ~Scheduler = Local::take();
|
||||
do scheduler.deschedule_running_task_and_then |_, task| {
|
||||
cx.task = Some(task);
|
||||
@ -244,11 +243,9 @@ struct Ctx { status: c_int, task: Option<BlockedTask> }
|
||||
};
|
||||
|
||||
extern fn connect_cb(req: *uvll::uv_connect_t, status: c_int) {
|
||||
let _req = Request::wrap(req);
|
||||
let req = Request::wrap(req);
|
||||
if status == uvll::ECANCELED { return }
|
||||
let cx: &mut Ctx = unsafe {
|
||||
cast::transmute(uvll::get_data_for_req(req))
|
||||
};
|
||||
let cx: &mut Ctx = unsafe { cast::transmute(req.get_data()) };
|
||||
cx.status = status;
|
||||
let scheduler: ~Scheduler = Local::take();
|
||||
scheduler.resume_blocked_task_immediately(cx.task.take_unwrap());
|
||||
@ -328,7 +325,7 @@ pub fn bind(loop_: &mut Loop, address: SocketAddr)
|
||||
{
|
||||
let handle = unsafe { uvll::malloc_handle(uvll::UV_TCP) };
|
||||
assert_eq!(unsafe {
|
||||
uvll::uv_tcp_init(loop_.native_handle(), handle)
|
||||
uvll::uv_tcp_init(loop_.handle, handle)
|
||||
}, 0);
|
||||
let l = ~TcpListener {
|
||||
home: get_handle_to_current_scheduler!(),
|
||||
@ -385,7 +382,7 @@ fn listen(mut ~self) -> Result<~rtio::RtioTcpAcceptor, IoError> {
|
||||
extern fn listen_cb(server: *uvll::uv_stream_t, status: c_int) {
|
||||
let msg = match status {
|
||||
0 => {
|
||||
let loop_ = NativeHandle::from_native_handle(unsafe {
|
||||
let loop_ = Loop::wrap(unsafe {
|
||||
uvll::get_loop_for_uv_handle(server)
|
||||
});
|
||||
let client = TcpWatcher::new(&loop_);
|
||||
@ -471,7 +468,7 @@ pub fn bind(loop_: &Loop, address: SocketAddr)
|
||||
home: get_handle_to_current_scheduler!(),
|
||||
};
|
||||
assert_eq!(unsafe {
|
||||
uvll::uv_udp_init(loop_.native_handle(), udp.handle)
|
||||
uvll::uv_udp_init(loop_.handle, udp.handle)
|
||||
}, 0);
|
||||
let result = socket_addr_as_uv_socket_addr(address, |addr| unsafe {
|
||||
match addr {
|
||||
|
@ -19,7 +19,7 @@
|
||||
use std::rt::tube::Tube;
|
||||
|
||||
use stream::StreamWatcher;
|
||||
use super::{Loop, UvError, NativeHandle, uv_error_to_io_error, UvHandle, Request};
|
||||
use super::{Loop, UvError, UvHandle, Request, uv_error_to_io_error};
|
||||
use uvio::HomingIO;
|
||||
use uvll;
|
||||
|
||||
@ -55,7 +55,7 @@ pub fn alloc(loop_: &Loop, ipc: bool) -> *uvll::uv_pipe_t {
|
||||
let handle = uvll::malloc_handle(uvll::UV_NAMED_PIPE);
|
||||
assert!(!handle.is_null());
|
||||
let ipc = ipc as libc::c_int;
|
||||
assert_eq!(uvll::uv_pipe_init(loop_.native_handle(), handle, ipc), 0);
|
||||
assert_eq!(uvll::uv_pipe_init(loop_.handle, handle, ipc), 0);
|
||||
handle
|
||||
}
|
||||
}
|
||||
@ -196,7 +196,7 @@ fn uv_handle(&self) -> *uvll::uv_pipe_t { self.pipe }
|
||||
extern fn listen_cb(server: *uvll::uv_stream_t, status: libc::c_int) {
|
||||
let msg = match status {
|
||||
0 => {
|
||||
let loop_ = NativeHandle::from_native_handle(unsafe {
|
||||
let loop_ = Loop::wrap(unsafe {
|
||||
uvll::get_loop_for_uv_handle(server)
|
||||
});
|
||||
let client = PipeWatcher::alloc(&loop_, false);
|
||||
|
@ -19,7 +19,7 @@
|
||||
use std::rt::sched::{Scheduler, SchedHandle};
|
||||
use std::vec;
|
||||
|
||||
use super::{Loop, NativeHandle, UvHandle, UvError, uv_error_to_io_error};
|
||||
use super::{Loop, UvHandle, UvError, uv_error_to_io_error};
|
||||
use uvio::HomingIO;
|
||||
use uvll;
|
||||
use pipe::PipeWatcher;
|
||||
@ -77,7 +77,7 @@ pub fn spawn(loop_: &Loop, config: ProcessConfig)
|
||||
|
||||
let handle = UvHandle::alloc(None::<Process>, uvll::UV_PROCESS);
|
||||
match unsafe {
|
||||
uvll::uv_spawn(loop_.native_handle(), handle, options)
|
||||
uvll::uv_spawn(loop_.handle, handle, options)
|
||||
} {
|
||||
0 => {
|
||||
let process = ~Process {
|
||||
|
@ -32,7 +32,8 @@ pub fn new(loop_: &mut Loop, signum: Signum,
|
||||
channel: SharedChan<Signum>) -> Result<~SignalWatcher, UvError> {
|
||||
let handle = UvHandle::alloc(None::<SignalWatcher>, uvll::UV_SIGNAL);
|
||||
assert_eq!(unsafe {
|
||||
uvll::uv_signal_init(loop_.native_handle(), handle)
|
||||
uvll::uv_signal_init(loop_.handle, handle)
|
||||
|
||||
}, 0);
|
||||
|
||||
match unsafe { uvll::uv_signal_start(handle, signal_cb, signum as c_int) } {
|
||||
|
@ -201,8 +201,8 @@ pub fn close(&mut self, synchronous: bool) {
|
||||
let req = Request::wrap(req);
|
||||
let wcx: &mut WriteContext = unsafe { cast::transmute(req.get_data()) };
|
||||
wcx.result = status;
|
||||
req.defuse();
|
||||
|
||||
let sched: ~Scheduler = Local::take();
|
||||
sched.resume_blocked_task_immediately(wcx.task.take_unwrap());
|
||||
req.defuse();
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
use std::rt::sched::{Scheduler, SchedHandle};
|
||||
|
||||
use uvll;
|
||||
use super::{Loop, NativeHandle, UvHandle};
|
||||
use super::{Loop, UvHandle};
|
||||
use uvio::HomingIO;
|
||||
|
||||
pub struct TimerWatcher {
|
||||
@ -35,7 +35,7 @@ impl TimerWatcher {
|
||||
pub fn new(loop_: &mut Loop) -> ~TimerWatcher {
|
||||
let handle = UvHandle::alloc(None::<TimerWatcher>, uvll::UV_TIMER);
|
||||
assert_eq!(unsafe {
|
||||
uvll::uv_timer_init(loop_.native_handle(), handle)
|
||||
uvll::uv_timer_init(loop_.handle, handle)
|
||||
}, 0);
|
||||
let me = ~TimerWatcher {
|
||||
handle: handle,
|
||||
|
@ -33,7 +33,7 @@ pub fn new(loop_: &Loop, fd: libc::c_int, readable: bool)
|
||||
let handle = UvHandle::alloc(None::<TtyWatcher>, uvll::UV_TTY);
|
||||
|
||||
match unsafe {
|
||||
uvll::uv_tty_init(loop_.native_handle(), handle, fd as libc::c_int,
|
||||
uvll::uv_tty_init(loop_.handle, handle, fd as libc::c_int,
|
||||
readable as libc::c_int)
|
||||
} {
|
||||
0 => {
|
||||
|
@ -12,18 +12,18 @@
|
||||
use std::cast::transmute;
|
||||
use std::cast;
|
||||
use std::comm::{SharedChan, GenericChan};
|
||||
use std::libc;
|
||||
use std::libc::c_int;
|
||||
use std::str;
|
||||
use std::rt::io;
|
||||
use std::libc;
|
||||
use std::path::Path;
|
||||
use std::rt::io::IoError;
|
||||
use std::rt::io::net::ip::SocketAddr;
|
||||
use std::rt::io::process::ProcessConfig;
|
||||
use std::rt::io;
|
||||
use std::rt::local::Local;
|
||||
use std::rt::rtio::*;
|
||||
use std::rt::sched::{Scheduler, SchedHandle};
|
||||
use std::rt::task::Task;
|
||||
use std::path::Path;
|
||||
use std::str;
|
||||
use std::libc::{O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY,
|
||||
S_IRUSR, S_IWUSR};
|
||||
use std::rt::io::{FileMode, FileAccess, Open, Append, Truncate, Read, Write,
|
||||
@ -39,11 +39,8 @@
|
||||
#[cfg(test)] use std::rt::comm::oneshot;
|
||||
|
||||
use super::*;
|
||||
use idle::IdleWatcher;
|
||||
use addrinfo::GetAddrInfoRequest;
|
||||
|
||||
// XXX we should not be calling uvll functions in here.
|
||||
|
||||
pub trait HomingIO {
|
||||
|
||||
fn home<'r>(&'r mut self) -> &'r mut SchedHandle;
|
||||
@ -238,7 +235,7 @@ fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>,
|
||||
|
||||
fn fs_from_raw_fd(&mut self, fd: c_int,
|
||||
close: CloseBehavior) -> ~RtioFileStream {
|
||||
let loop_ = Loop {handle: self.uv_loop().native_handle()};
|
||||
let loop_ = Loop::wrap(self.uv_loop().handle);
|
||||
~FileWatcher::new(loop_, fd, close) as ~RtioFileStream
|
||||
}
|
||||
|
||||
|
@ -107,14 +107,16 @@ pub fn log(_level: u32, args: &fmt::Arguments) {
|
||||
let optional_task: Option<*mut Task> = Local::try_unsafe_borrow();
|
||||
match optional_task {
|
||||
Some(local) => {
|
||||
// Use the available logger
|
||||
(*local).logger.log(args);
|
||||
}
|
||||
None => {
|
||||
// There is no logger anywhere, just write to stderr
|
||||
let mut logger = StdErrLogger::new();
|
||||
logger.log(args);
|
||||
match (*local).logger {
|
||||
// Use the available logger if we have one
|
||||
Some(ref mut logger) => return logger.log(args),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
// There is no logger anywhere, just write to stderr
|
||||
let mut logger = StdErrLogger::new();
|
||||
logger.log(args);
|
||||
}
|
||||
}
|
||||
|
@ -172,20 +172,18 @@ pub trait Logger {
|
||||
/// This logger emits output to the stderr of the process, and contains a lazily
|
||||
/// initialized event-loop driven handle to the stream.
|
||||
pub struct StdErrLogger {
|
||||
priv handle: Option<LineBufferedWriter<StdWriter>>,
|
||||
priv handle: LineBufferedWriter<StdWriter>,
|
||||
}
|
||||
|
||||
impl StdErrLogger {
|
||||
pub fn new() -> StdErrLogger { StdErrLogger { handle: None } }
|
||||
pub fn new() -> StdErrLogger {
|
||||
StdErrLogger { handle: LineBufferedWriter::new(io::stderr()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Logger for StdErrLogger {
|
||||
fn log(&mut self, args: &fmt::Arguments) {
|
||||
// First time logging? Get a handle to the stderr of this process.
|
||||
if self.handle.is_none() {
|
||||
self.handle = Some(LineBufferedWriter::new(io::stderr()));
|
||||
}
|
||||
fmt::writeln(self.handle.get_mut_ref() as &mut io::Writer, args);
|
||||
fmt::writeln(&mut self.handle as &mut io::Writer, args);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ macro_rules! rtassert (
|
||||
( $arg:expr ) => ( {
|
||||
if ::rt::util::ENFORCE_SANITY {
|
||||
if !$arg {
|
||||
rtabort!("assertion failed: {}", stringify!($arg));
|
||||
rtabort!(" assertion failed: {}", stringify!($arg));
|
||||
}
|
||||
}
|
||||
} )
|
||||
@ -42,7 +42,8 @@ macro_rules! rtassert (
|
||||
|
||||
|
||||
macro_rules! rtabort (
|
||||
($($msg:tt)*) => ( {
|
||||
::rt::util::abort(format!($($msg)*));
|
||||
($msg:expr $($arg:tt)*) => ( {
|
||||
::rt::util::abort(format!(concat!(file!(), ":", line!(), " ", $msg)
|
||||
$($arg)*));
|
||||
} )
|
||||
)
|
||||
|
@ -50,7 +50,7 @@ pub struct Task {
|
||||
heap: LocalHeap,
|
||||
priv gc: GarbageCollector,
|
||||
storage: LocalStorage,
|
||||
logger: StdErrLogger,
|
||||
logger: Option<StdErrLogger>,
|
||||
unwinder: Unwinder,
|
||||
taskgroup: Option<Taskgroup>,
|
||||
death: Death,
|
||||
@ -180,7 +180,7 @@ pub fn new_sched_task() -> Task {
|
||||
heap: LocalHeap::new(),
|
||||
gc: GarbageCollector,
|
||||
storage: LocalStorage(None),
|
||||
logger: StdErrLogger::new(),
|
||||
logger: None,
|
||||
unwinder: Unwinder { unwinding: false, cause: None },
|
||||
taskgroup: None,
|
||||
death: Death::new(),
|
||||
@ -215,7 +215,7 @@ pub fn new_root_homed(stack_pool: &mut StackPool,
|
||||
heap: LocalHeap::new(),
|
||||
gc: GarbageCollector,
|
||||
storage: LocalStorage(None),
|
||||
logger: StdErrLogger::new(),
|
||||
logger: None,
|
||||
unwinder: Unwinder { unwinding: false, cause: None },
|
||||
taskgroup: None,
|
||||
death: Death::new(),
|
||||
@ -238,7 +238,7 @@ pub fn new_child_homed(&mut self,
|
||||
heap: LocalHeap::new(),
|
||||
gc: GarbageCollector,
|
||||
storage: LocalStorage(None),
|
||||
logger: StdErrLogger::new(),
|
||||
logger: None,
|
||||
unwinder: Unwinder { unwinding: false, cause: None },
|
||||
taskgroup: None,
|
||||
// FIXME(#7544) make watching optional
|
||||
@ -320,6 +320,7 @@ pub fn run(&mut self, f: &fn()) {
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
self.logger.take();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user