diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-11-02 00:30:13 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-11-02 00:57:44 -0700 |
| commit | b62844e755d36fddff303c0639303bb0f56c5d41 (patch) | |
| tree | a01430b63b38931045028a03cfbd519c753c87a8 /src/libcore/pipes.rs | |
| parent | a90020fe8dd8be8615df82e6294408bfed82a767 (diff) | |
core: peek returns false for terminated pipes. Closes #3905
Diffstat (limited to 'src/libcore/pipes.rs')
| -rw-r--r-- | src/libcore/pipes.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 2c2cd6a528a..5385d755219 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -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(); + } } |
