From 620ab3853abf99ecea3a3d055f47cd6d06433c95 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 17 Oct 2013 21:08:48 -0700 Subject: Test fixes and merge conflicts --- src/libstd/os.rs | 4 ++- src/libstd/rt/io/native/file.rs | 18 +++++++++++--- src/libstd/rt/io/net/addrinfo.rs | 7 ++++-- src/libstd/rt/util.rs | 20 +++++++++------ src/libstd/rt/uv/addrinfo.rs | 14 +++++++++-- src/libstd/rt/uv/mod.rs | 7 ++++++ src/libstd/rt/uv/net.rs | 53 ++++++++++++++++++++-------------------- src/libstd/rt/uv/uvio.rs | 2 +- src/libstd/rt/uv/uvll.rs | 25 ++++++++++--------- src/libstd/run.rs | 17 +++---------- 10 files changed, 98 insertions(+), 69 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 99930b39a65..1f32c6a0a35 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -189,6 +189,8 @@ pub fn env() -> ~[(~str,~str)] { #[cfg(windows)] unsafe fn get_env_pairs() -> ~[~str] { #[fixed_stack_segment]; #[inline(never)]; + use c_str; + use str::StrSlice; use libc::funcs::extra::kernel32::{ GetEnvironmentStringsA, @@ -201,7 +203,7 @@ pub fn env() -> ~[(~str,~str)] { } let mut result = ~[]; do c_str::from_c_multistring(ch as *libc::c_char, None) |cstr| { - result.push(cstr.as_str().to_owned()); + result.push(cstr.as_str().unwrap().to_owned()); }; FreeEnvironmentStringsA(ch); result diff --git a/src/libstd/rt/io/native/file.rs b/src/libstd/rt/io/native/file.rs index a2b2289679a..ba819df071a 100644 --- a/src/libstd/rt/io/native/file.rs +++ b/src/libstd/rt/io/native/file.rs @@ -17,9 +17,18 @@ use os; use prelude::*; use super::super::*; -fn raise_error() { +#[cfg(windows)] +fn get_err(errno: i32) -> (IoErrorKind, &'static str) { + match errno { + libc::EOF => (EndOfFile, "end of file"), + _ => (OtherIoError, "unknown error"), + } +} + +#[cfg(not(windows))] +fn get_err(errno: i32) -> (IoErrorKind, &'static str) { // XXX: this should probably be a bit more descriptive... - let (kind, desc) = match os::errno() as i32 { + match errno { libc::EOF => (EndOfFile, "end of file"), // These two constants can have the same value on some systems, but @@ -28,8 +37,11 @@ fn raise_error() { (ResourceUnavailable, "resource temporarily unavailable"), _ => (OtherIoError, "unknown error"), - }; + } +} +fn raise_error() { + let (kind, desc) = get_err(os::errno() as i32); io_error::cond.raise(IoError { kind: kind, desc: desc, diff --git a/src/libstd/rt/io/net/addrinfo.rs b/src/libstd/rt/io/net/addrinfo.rs index e0c92730cd9..27cf9781c9c 100644 --- a/src/libstd/rt/io/net/addrinfo.rs +++ b/src/libstd/rt/io/net/addrinfo.rs @@ -91,8 +91,11 @@ pub fn get_host_addresses(host: &str) -> Option<~[IpAddr]> { /// # Failure /// /// On failure, this will raise on the `io_error` condition. -pub fn lookup(hostname: Option<&str>, servname: Option<&str>, - hint: Option) -> Option<~[Info]> { +/// +/// XXX: this is not public because the `Hint` structure is not ready for public +/// consumption just yet. +fn lookup(hostname: Option<&str>, servname: Option<&str>, + hint: Option) -> Option<~[Info]> { do with_local_io |io| { match io.get_host_addresses(hostname, servname, hint) { Ok(i) => Some(i), diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index e859f8e4fdb..070985fb0a5 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -72,16 +72,22 @@ pub fn default_sched_threads() -> uint { pub fn dumb_println(args: &fmt::Arguments) { use rt::io::native::stdio::stderr; use rt::io::{Writer, io_error, ResourceUnavailable}; + use rt::task::Task; + use rt::local::Local; let mut out = stderr(); - let mut again = true; - do io_error::cond.trap(|e| { - again = e.kind == ResourceUnavailable; - }).inside { - while again { - again = false; - fmt::writeln(&mut out as &mut Writer, args); + if Local::exists(None::) { + let mut again = true; + do io_error::cond.trap(|e| { + again = e.kind == ResourceUnavailable; + }).inside { + while again { + again = false; + fmt::writeln(&mut out as &mut Writer, args); + } } + } else { + fmt::writeln(&mut out as &mut Writer, args); } } diff --git a/src/libstd/rt/uv/addrinfo.rs b/src/libstd/rt/uv/addrinfo.rs index 7556d7db665..a1593d5c8db 100644 --- a/src/libstd/rt/uv/addrinfo.rs +++ b/src/libstd/rt/uv/addrinfo.rs @@ -73,13 +73,14 @@ impl GetAddrInfoRequest { cb(req, addrinfo, err) }; - let hint = hints.map(|hint| unsafe { + let hint = hints.map(|hint| { let mut flags = 0; do each_ai_flag |cval, aival| { if hint.flags & (aival as uint) != 0 { flags |= cval as i32; } } + /* XXX: do we really want to support these? let socktype = match hint.socktype { Some(ai::Stream) => uvll::rust_SOCK_STREAM(), Some(ai::Datagram) => uvll::rust_SOCK_DGRAM(), @@ -91,6 +92,9 @@ impl GetAddrInfoRequest { Some(ai::TCP) => uvll::rust_IPPROTO_TCP(), _ => 0, }; + */ + let socktype = 0; + let protocol = 0; uvll::addrinfo { ai_flags: flags, @@ -167,7 +171,8 @@ impl GetAddrInfoRequest { } } -fn each_ai_flag(f: &fn(c_int, ai::Flag)) { +fn each_ai_flag(_f: &fn(c_int, ai::Flag)) { + /* XXX: do we really want to support these? unsafe { f(uvll::rust_AI_ADDRCONFIG(), ai::AddrConfig); f(uvll::rust_AI_ALL(), ai::All); @@ -177,6 +182,7 @@ fn each_ai_flag(f: &fn(c_int, ai::Flag)) { f(uvll::rust_AI_PASSIVE(), ai::Passive); f(uvll::rust_AI_V4MAPPED(), ai::V4Mapped); } + */ } // Traverse the addrinfo linked list, producing a vector of Rust socket addresses @@ -197,6 +203,7 @@ pub fn accum_addrinfo(addr: &net::UvAddrInfo) -> ~[ai::Info] { } } + /* XXX: do we really want to support these let protocol = match (*addr).ai_protocol { p if p == uvll::rust_IPPROTO_UDP() => Some(ai::UDP), p if p == uvll::rust_IPPROTO_TCP() => Some(ai::TCP), @@ -208,6 +215,9 @@ pub fn accum_addrinfo(addr: &net::UvAddrInfo) -> ~[ai::Info] { p if p == uvll::rust_SOCK_RAW() => Some(ai::Raw), _ => None, }; + */ + let protocol = None; + let socktype = None; addrs.push(ai::Info { address: rustaddr, diff --git a/src/libstd/rt/uv/mod.rs b/src/libstd/rt/uv/mod.rs index 18c99157707..88bb28d3763 100644 --- a/src/libstd/rt/uv/mod.rs +++ b/src/libstd/rt/uv/mod.rs @@ -336,6 +336,13 @@ pub fn status_to_maybe_uv_error(status: c_int) -> Option /// The uv buffer type pub type Buf = uvll::uv_buf_t; +pub fn empty_buf() -> Buf { + uvll::uv_buf_t { + base: null(), + len: 0, + } +} + /// Borrow a slice to a Buf pub fn slice_to_uv_buf(v: &[u8]) -> Buf { let data = vec::raw::to_ptr(v); diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index 22d7c9c61b3..77de8348c14 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -14,7 +14,7 @@ use rt::uv::uvll; use rt::uv::uvll::*; use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback, UdpSendCallback}; use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle, - status_to_maybe_uv_error, vec_to_uv_buf}; + status_to_maybe_uv_error, empty_buf}; use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr}; use vec; use str; @@ -119,23 +119,17 @@ impl Watcher for StreamWatcher { } impl StreamWatcher { pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) { - { - let data = self.get_watcher_data(); - data.alloc_cb = Some(alloc); - data.read_cb = Some(cb); - } - - let ret = unsafe { uvll::read_start(self.native_handle(), alloc_cb, read_cb) }; - - if ret != 0 { - // uvll::read_start failed, so read_cb will not be called. - // Call it manually for scheduling. - call_read_cb(self.native_handle(), ret as ssize_t); - } - - fn call_read_cb(stream: *uvll::uv_stream_t, errno: ssize_t) { - #[fixed_stack_segment]; #[inline(never)]; - read_cb(stream, errno, vec_to_uv_buf(~[])); + unsafe { + match uvll::read_start(self.native_handle(), alloc_cb, read_cb) { + 0 => { + let data = self.get_watcher_data(); + data.alloc_cb = Some(alloc); + data.read_cb = Some(cb); + } + n => { + cb(*self, 0, empty_buf(), Some(UvError(n))) + } + } } extern fn alloc_cb(stream: *uvll::uv_stream_t, suggested_size: size_t) -> Buf { @@ -163,16 +157,21 @@ impl StreamWatcher { } pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) { - { - let data = self.get_watcher_data(); - assert!(data.write_cb.is_none()); - data.write_cb = Some(cb); - } - let req = WriteRequest::new(); - unsafe { - assert_eq!(0, uvll::write(req.native_handle(), self.native_handle(), [buf], write_cb)); - } + return unsafe { + match uvll::write(req.native_handle(), self.native_handle(), + [buf], write_cb) { + 0 => { + let data = self.get_watcher_data(); + assert!(data.write_cb.is_none()); + data.write_cb = Some(cb); + } + n => { + req.delete(); + cb(*self, Some(UvError(n))) + } + } + }; extern fn write_cb(req: *uvll::uv_write_t, status: c_int) { let write_request: WriteRequest = NativeHandle::from_native_handle(req); diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 0d22aa51be5..f12b1bce9e6 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -229,7 +229,7 @@ impl EventLoop for UvEventLoop { } } - fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback{ + fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback { ~UvRemoteCallback::new(self.uvio.uv_loop(), f) as ~RemoteCallback } diff --git a/src/libstd/rt/uv/uvll.rs b/src/libstd/rt/uv/uvll.rs index 8f8aea9d121..f3e14dc314b 100644 --- a/src/libstd/rt/uv/uvll.rs +++ b/src/libstd/rt/uv/uvll.rs @@ -1146,17 +1146,18 @@ extern { height: *c_int) -> c_int; fn rust_uv_guess_handle(fd: c_int) -> uv_handle_type; + // XXX: see comments in addrinfo.rs // These should all really be constants... - #[rust_stack] pub fn rust_SOCK_STREAM() -> c_int; - #[rust_stack] pub fn rust_SOCK_DGRAM() -> c_int; - #[rust_stack] pub fn rust_SOCK_RAW() -> c_int; - #[rust_stack] pub fn rust_IPPROTO_UDP() -> c_int; - #[rust_stack] pub fn rust_IPPROTO_TCP() -> c_int; - #[rust_stack] pub fn rust_AI_ADDRCONFIG() -> c_int; - #[rust_stack] pub fn rust_AI_ALL() -> c_int; - #[rust_stack] pub fn rust_AI_CANONNAME() -> c_int; - #[rust_stack] pub fn rust_AI_NUMERICHOST() -> c_int; - #[rust_stack] pub fn rust_AI_NUMERICSERV() -> c_int; - #[rust_stack] pub fn rust_AI_PASSIVE() -> c_int; - #[rust_stack] pub fn rust_AI_V4MAPPED() -> c_int; + //#[rust_stack] pub fn rust_SOCK_STREAM() -> c_int; + //#[rust_stack] pub fn rust_SOCK_DGRAM() -> c_int; + //#[rust_stack] pub fn rust_SOCK_RAW() -> c_int; + //#[rust_stack] pub fn rust_IPPROTO_UDP() -> c_int; + //#[rust_stack] pub fn rust_IPPROTO_TCP() -> c_int; + //#[rust_stack] pub fn rust_AI_ADDRCONFIG() -> c_int; + //#[rust_stack] pub fn rust_AI_ALL() -> c_int; + //#[rust_stack] pub fn rust_AI_CANONNAME() -> c_int; + //#[rust_stack] pub fn rust_AI_NUMERICHOST() -> c_int; + //#[rust_stack] pub fn rust_AI_NUMERICSERV() -> c_int; + //#[rust_stack] pub fn rust_AI_PASSIVE() -> c_int; + //#[rust_stack] pub fn rust_AI_V4MAPPED() -> c_int; } diff --git a/src/libstd/run.rs b/src/libstd/run.rs index c4cb8be2061..d5f8e82b90f 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -19,6 +19,7 @@ use libc; use prelude::*; use rt::io::native::process; use rt::io; +use rt::io::extensions::ReaderUtil; use task; /** @@ -189,18 +190,6 @@ impl Process { let output = Cell::new(self.inner.take_output()); let error = Cell::new(self.inner.take_error()); - fn read_everything(r: &mut io::Reader) -> ~[u8] { - let mut ret = ~[]; - let mut buf = [0, ..1024]; - loop { - match r.read(buf) { - Some(n) => { ret.push_all(buf.slice_to(n)); } - None => break - } - } - return ret; - } - // Spawn two entire schedulers to read both stdout and sterr // in parallel so we don't deadlock while blocking on one // or the other. FIXME (#2625): Surely there's a much more @@ -210,13 +199,13 @@ impl Process { let ch_clone = ch.clone(); do task::spawn_sched(task::SingleThreaded) { match error.take() { - Some(ref mut e) => ch.send((2, read_everything(*e))), + Some(ref mut e) => ch.send((2, e.read_to_end())), None => ch.send((2, ~[])) } } do task::spawn_sched(task::SingleThreaded) { match output.take() { - Some(ref mut e) => ch_clone.send((1, read_everything(*e))), + Some(ref mut e) => ch_clone.send((1, e.read_to_end())), None => ch_clone.send((1, ~[])) } } -- cgit 1.4.1-3-g733a5