Skip to content

Commit 8ca7142

Browse files
committed
---
yaml --- r: 106751 b: refs/heads/try c: 80f92f5 h: refs/heads/master i: 106749: bfd3833 106747: bcace8d 106743: cc2d9cb 106735: c3a4c7e 106719: bb11a85 106687: 62afca6 106623: 64963aa 106495: 546b03f v: v3
1 parent 94389ce commit 8ca7142

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b8601a3d8b91ad3b653d143307611f2f5c75617e
5-
refs/heads/try: 3316a0e6b2ad9352bab58e7c046ef3d212411d82
5+
refs/heads/try: 80f92f5c5fedadd131842977c0b9b21806f3902f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/comm/oneshot.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,19 @@ impl<T: Send> Packet<T> {
339339
DATA => Ok(true),
340340

341341
// If the other end has hung up, then we have complete ownership
342-
// of the port. We need to check to see if there was an upgrade
343-
// requested, and if so, the other end needs to have its selection
344-
// aborted.
342+
// of the port. First, check if there was data waiting for us. This
343+
// is possible if the other end sent something and then hung up.
344+
//
345+
// We then need to check to see if there was an upgrade requested,
346+
// and if so, the upgraded port needs to have its selection aborted.
345347
DISCONNECTED => {
346-
assert!(self.data.is_none());
347-
match mem::replace(&mut self.upgrade, SendUsed) {
348-
GoUp(port) => Err(port),
349-
_ => Ok(true),
348+
if self.data.is_some() {
349+
Ok(true)
350+
} else {
351+
match mem::replace(&mut self.upgrade, SendUsed) {
352+
GoUp(port) => Err(port),
353+
_ => Ok(true),
354+
}
350355
}
351356
}
352357

branches/try/src/libstd/comm/select.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,4 +597,56 @@ mod test {
597597
unsafe { h.add(); }
598598
assert_eq!(s.wait2(false), h.id);
599599
})
600+
601+
test!(fn oneshot_data_waiting() {
602+
let (p, c) = Chan::new();
603+
let (p2, c2) = Chan::new();
604+
spawn(proc() {
605+
select! {
606+
() = p.recv() => {}
607+
}
608+
c2.send(());
609+
});
610+
611+
for _ in range(0, 100) { task::deschedule() }
612+
c.send(());
613+
p2.recv();
614+
})
615+
616+
test!(fn stream_data_waiting() {
617+
let (p, c) = Chan::new();
618+
let (p2, c2) = Chan::new();
619+
c.send(());
620+
c.send(());
621+
p.recv();
622+
p.recv();
623+
spawn(proc() {
624+
select! {
625+
() = p.recv() => {}
626+
}
627+
c2.send(());
628+
});
629+
630+
for _ in range(0, 100) { task::deschedule() }
631+
c.send(());
632+
p2.recv();
633+
})
634+
635+
test!(fn shared_data_waiting() {
636+
let (p, c) = Chan::new();
637+
let (p2, c2) = Chan::new();
638+
drop(c.clone());
639+
c.send(());
640+
p.recv();
641+
spawn(proc() {
642+
select! {
643+
() = p.recv() => {}
644+
}
645+
c2.send(());
646+
});
647+
648+
for _ in range(0, 100) { task::deschedule() }
649+
c.send(());
650+
p2.recv();
651+
})
600652
}

0 commit comments

Comments
 (0)