core: peek returns false for terminated pipes. Closes #3905

This commit is contained in:
Brian Anderson 2012-11-02 00:30:13 -07:00
parent a90020fe8d
commit b62844e755

View file

@ -511,9 +511,9 @@ pub fn try_recv<T: Send, Tbuffer: Send>(p: RecvPacketBuffered<T, Tbuffer>)
/// Returns true if messages are available.
pub pure fn peek<T: Send, Tb: Send>(p: &RecvPacketBuffered<T, Tb>) -> 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<int>, Port<int>) = stream();
{
// Destroy the channel
let _chan = move chan;
}
assert !port.peek();
}
}