From b62844e755d36fddff303c0639303bb0f56c5d41 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 2 Nov 2012 00:30:13 -0700 Subject: [PATCH] core: peek returns false for terminated pipes. Closes #3905 --- src/libcore/pipes.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 2c2cd6a528aa..5385d7552193 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -511,9 +511,9 @@ pub fn try_recv(p: RecvPacketBuffered) /// Returns true if messages are available. pub pure fn peek(p: &RecvPacketBuffered) -> bool { match unsafe {(*p.header()).state} { - Empty => false, + Empty | Terminated => false, Blocked => fail ~"peeking on blocked packet", - Full | Terminated => true + Full => true } } @@ -1234,4 +1234,16 @@ pub mod test { recv_one(move p) } + + #[test] + fn test_peek_terminated() { + let (chan, port): (Chan, Port) = stream(); + + { + // Destroy the channel + let _chan = move chan; + } + + assert !port.peek(); + } }