Auto merge of #34731 - GGist:fix_sync_try_recv, r=alexcrichton
Check for data in Receiver::try_recv before reporting disconnect Fixes #34711 r? @alexcrichton
This commit is contained in:
commit
46e7f4b8c5
@ -2180,6 +2180,15 @@ mod sync_tests {
|
||||
assert!(rx.recv().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oneshot_single_thread_try_recv_closed_with_data() {
|
||||
let (tx, rx) = sync_channel::<i32>(1);
|
||||
tx.send(10).unwrap();
|
||||
drop(tx);
|
||||
assert_eq!(rx.try_recv(), Ok(10));
|
||||
assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oneshot_single_thread_peek_data() {
|
||||
let (tx, rx) = sync_channel::<i32>(1);
|
||||
|
@ -309,7 +309,7 @@ impl<T> Packet<T> {
|
||||
let mut guard = self.lock.lock().unwrap();
|
||||
|
||||
// Easy cases first
|
||||
if guard.disconnected { return Err(Disconnected) }
|
||||
if guard.disconnected && guard.buf.size() == 0 { return Err(Disconnected) }
|
||||
if guard.buf.size() == 0 { return Err(Empty) }
|
||||
|
||||
// Be sure to wake up neighbors
|
||||
|
Loading…
Reference in New Issue
Block a user