From 3f4c6cead67cedea5042d5ba84fb490dfee5462a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 4 Aug 2013 00:40:10 -0700 Subject: Remove old tests and code for `select` Not compatible with newsched --- src/libstd/comm.rs | 110 +--------------------------------------------------- src/libstd/pipes.rs | 44 --------------------- 2 files changed, 2 insertions(+), 152 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index a0731dc3494..4356f1143da 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -14,7 +14,6 @@ Message passing #[allow(missing_doc)]; -use cast::transmute; use either::{Either, Left, Right}; use kinds::Send; use option::{Option, Some}; @@ -23,12 +22,6 @@ pub use rt::comm::SendDeferred; use rtcomm = rt::comm; use rt; -use pipes::{wait_many, PacketHeader}; - -// FIXME #5160: Making this public exposes some plumbing from -// pipes. Needs some refactoring -pub use pipes::Selectable; - /// A trait for things that can send multiple messages. pub trait GenericChan { /// Sends a message. @@ -146,15 +139,6 @@ impl Peekable for Port { } } -impl Selectable for Port { - fn header(&mut self) -> *mut PacketHeader { - match self.inner { - Left(ref mut port) => port.header(), - Right(_) => fail!("can't select on newsched ports") - } - } -} - /// A channel that can be shared between many senders. pub struct SharedChan { inner: Either>, rtcomm::SharedChan> @@ -318,8 +302,8 @@ mod pipesy { use kinds::Send; use option::{Option, Some, None}; - use pipes::{recv, try_recv, peek, PacketHeader}; - use super::{GenericChan, GenericSmartChan, GenericPort, Peekable, Selectable}; + use pipes::{recv, try_recv, peek}; + use super::{GenericChan, GenericSmartChan, GenericPort, Peekable}; use cast::transmute_mut; /*proto! oneshot ( @@ -651,80 +635,6 @@ mod pipesy { } } - impl Selectable for Port { - fn header(&mut self) -> *mut PacketHeader { - match self.endp { - Some(ref mut endp) => endp.header(), - None => fail!("peeking empty stream") - } - } -} - -} - -/// Returns the index of an endpoint that is ready to receive. -pub fn selecti(endpoints: &mut [T]) -> uint { - wait_many(endpoints) -} - -/// Returns 0 or 1 depending on which endpoint is ready to receive -pub fn select2i(a: &mut A, b: &mut B) - -> Either<(), ()> { - let mut endpoints = [ a.header(), b.header() ]; - match wait_many(endpoints) { - 0 => Left(()), - 1 => Right(()), - _ => fail!("wait returned unexpected index"), - } -} - -/// Receive a message from one of two endpoints. -pub trait Select2 { - /// Receive a message or return `None` if a connection closes. - fn try_select(&mut self) -> Either, Option>; - /// Receive a message or fail if a connection closes. - fn select(&mut self) -> Either; -} - -impl, - Right:Selectable + GenericPort> - Select2 - for (Left, Right) { - fn select(&mut self) -> Either { - // XXX: Bad borrow check workaround. - unsafe { - let this: &(Left, Right) = transmute(self); - match *this { - (ref lp, ref rp) => { - let lp: &mut Left = transmute(lp); - let rp: &mut Right = transmute(rp); - match select2i(lp, rp) { - Left(()) => Left(lp.recv()), - Right(()) => Right(rp.recv()), - } - } - } - } - } - - fn try_select(&mut self) -> Either, Option> { - // XXX: Bad borrow check workaround. - unsafe { - let this: &(Left, Right) = transmute(self); - match *this { - (ref lp, ref rp) => { - let lp: &mut Left = transmute(lp); - let rp: &mut Right = transmute(rp); - match select2i(lp, rp) { - Left(()) => Left (lp.try_recv()), - Right(()) => Right(rp.try_recv()), - } - } - } - } - } } #[cfg(test)] @@ -732,22 +642,6 @@ mod test { use either::Right; use super::{Chan, Port, oneshot, stream}; - #[test] - fn test_select2() { - let (p1, c1) = stream(); - let (p2, c2) = stream(); - - c1.send(~"abc"); - - let mut tuple = (p1, p2); - match tuple.select() { - Right(_) => fail!(), - _ => (), - } - - c2.send(123); - } - #[test] fn test_oneshot() { let (p, c) = oneshot(); diff --git a/src/libstd/pipes.rs b/src/libstd/pipes.rs index 1fd534825a5..78f937e058a 100644 --- a/src/libstd/pipes.rs +++ b/src/libstd/pipes.rs @@ -868,47 +868,3 @@ pub mod rt { pub fn make_some(val: T) -> Option { Some(val) } pub fn make_none() -> Option { None } } - -#[cfg(test)] -mod test { - use either::Right; - use comm::{Chan, Port, oneshot, recv_one, stream, Select2, - GenericChan, Peekable}; - - #[test] - fn test_select2() { - let (p1, c1) = stream(); - let (p2, c2) = stream(); - - c1.send(~"abc"); - - let mut tuple = (p1, p2); - match tuple.select() { - Right(_) => fail!(), - _ => (), - } - - c2.send(123); - } - - #[test] - fn test_oneshot() { - let (p, c) = oneshot(); - - c.send(()); - - recv_one(p) - } - - #[test] - fn test_peek_terminated() { - let (port, chan): (Port, Chan) = stream(); - - { - // Destroy the channel - let _chan = chan; - } - - assert!(!port.peek()); - } -} -- cgit 1.4.1-3-g733a5