core: peek returns false for terminated pipes. Closes #3905
This commit is contained in:
parent
a90020fe8d
commit
b62844e755
1 changed files with 14 additions and 2 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue