Skip to content

std: Relax an assertion in oneshot selection #12803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/libstd/comm/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,19 @@ impl<T: Send> Packet<T> {
DATA => Ok(true),

// If the other end has hung up, then we have complete ownership
// of the port. We need to check to see if there was an upgrade
// requested, and if so, the other end needs to have its selection
// aborted.
// of the port. First, check if there was data waiting for us. This
// is possible if the other end sent something and then hung up.
//
// We then need to check to see if there was an upgrade requested,
// and if so, the upgraded port needs to have its selection aborted.
DISCONNECTED => {
assert!(self.data.is_none());
match mem::replace(&mut self.upgrade, SendUsed) {
GoUp(port) => Err(port),
_ => Ok(true),
if self.data.is_some() {
Ok(true)
} else {
match mem::replace(&mut self.upgrade, SendUsed) {
GoUp(port) => Err(port),
_ => Ok(true),
}
}
}

Expand Down
52 changes: 52 additions & 0 deletions src/libstd/comm/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,56 @@ mod test {
unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id);
})

test!(fn oneshot_data_waiting() {
let (p, c) = Chan::new();
let (p2, c2) = Chan::new();
spawn(proc() {
select! {
() = p.recv() => {}
}
c2.send(());
});

for _ in range(0, 100) { task::deschedule() }
c.send(());
p2.recv();
})

test!(fn stream_data_waiting() {
let (p, c) = Chan::new();
let (p2, c2) = Chan::new();
c.send(());
c.send(());
p.recv();
p.recv();
spawn(proc() {
select! {
() = p.recv() => {}
}
c2.send(());
});

for _ in range(0, 100) { task::deschedule() }
c.send(());
p2.recv();
})

test!(fn shared_data_waiting() {
let (p, c) = Chan::new();
let (p2, c2) = Chan::new();
drop(c.clone());
c.send(());
p.recv();
spawn(proc() {
select! {
() = p.recv() => {}
}
c2.send(());
});

for _ in range(0, 100) { task::deschedule() }
c.send(());
p2.recv();
})
}