libcore: Remove mutable fields from pipes

This commit is contained in:
Patrick Walton 2013-05-03 14:20:34 -07:00
parent 803a4f45fa
commit 6a44482b17
4 changed files with 246 additions and 202 deletions

View file

@ -72,7 +72,7 @@ impl<T:Owned,U:Owned> Peekable<U> for DuplexStream<T, U> {
}
impl<T:Owned,U:Owned> Selectable for DuplexStream<T, U> {
fn header(&self) -> *pipes::PacketHeader {
fn header(&mut self) -> *mut pipes::PacketHeader {
self.port.header()
}
}

View file

@ -14,10 +14,11 @@ use uv;
use uv::iotask;
use uv::iotask::IoTask;
use core::libc;
use core::libc::c_void;
use core::cast::transmute;
use core::cast;
use core::comm::{stream, Chan, SharedChan, Port, select2i};
use core::libc::c_void;
use core::libc;
/**
* Wait for timeout period then send provided value over a channel
@ -120,22 +121,28 @@ pub fn sleep(iotask: &IoTask, msecs: uint) {
pub fn recv_timeout<T:Copy + Owned>(iotask: &IoTask,
msecs: uint,
wait_po: &Port<T>)
-> Option<T> {
let (timeout_po, timeout_ch) = stream::<()>();
-> Option<T> {
let mut (timeout_po, timeout_ch) = stream::<()>();
delayed_send(iotask, msecs, &timeout_ch, ());
// FIXME: This could be written clearer (#2618)
either::either(
|_| {
None
}, |_| {
Some(wait_po.recv())
}, &select2i(&timeout_po, wait_po)
)
// XXX: Workaround due to ports and channels not being &mut. They should
// be.
unsafe {
let wait_po = cast::transmute_mut(wait_po);
// FIXME: This could be written clearer (#2618)
either::either(
|_| {
None
}, |_| {
Some(wait_po.recv())
}, &select2i(&mut timeout_po, wait_po)
)
}
}
// INTERNAL API
extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t,
status: libc::c_int) {
extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t, status: libc::c_int) {
unsafe {
debug!(
"delayed_send_cb handle %? status %?", handle, status);