Skip to content

std: Make std::comm return types consistent #13448

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

Merged
merged 1 commit into from
Apr 12, 2014
Merged
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
7 changes: 3 additions & 4 deletions src/libgreen/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,6 @@ fn new_sched_rng() -> XorShiftRng {
mod test {
use rustuv;

use std::comm;
use std::task::TaskOpts;
use std::rt::task::Task;
use std::rt::local::Local;
Expand Down Expand Up @@ -1428,7 +1427,7 @@ mod test {
// This task should not be able to starve the sender;
// The sender should get stolen to another thread.
spawn(proc() {
while rx.try_recv() != comm::Data(()) { }
while rx.try_recv().is_err() { }
});

tx.send(());
Expand All @@ -1445,7 +1444,7 @@ mod test {
// This task should not be able to starve the other task.
// The sends should eventually yield.
spawn(proc() {
while rx1.try_recv() != comm::Data(()) {
while rx1.try_recv().is_err() {
tx2.send(());
}
});
Expand Down Expand Up @@ -1499,7 +1498,7 @@ mod test {
let mut val = 20;
while val > 0 {
val = po.recv();
ch.try_send(val - 1);
let _ = ch.send_opt(val - 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ mod tests {
let _tx = tx;
fail!()
});
assert_eq!(rx.recv_opt(), None);
assert_eq!(rx.recv_opt(), Err(()));
}

#[test]
Expand Down
9 changes: 4 additions & 5 deletions src/libnative/io/timer_other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
//!
//! Note that all time units in this file are in *milliseconds*.

use std::comm::Data;
use libc;
use std::mem;
use std::os;
Expand Down Expand Up @@ -119,7 +118,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
Some(timer) => timer, None => return
};
let tx = timer.tx.take_unwrap();
if tx.try_send(()) && timer.repeat {
if tx.send_opt(()).is_ok() && timer.repeat {
timer.tx = Some(tx);
timer.target += timer.interval;
insert(timer, active);
Expand Down Expand Up @@ -162,14 +161,14 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
1 => {
loop {
match messages.try_recv() {
Data(Shutdown) => {
Ok(Shutdown) => {
assert!(active.len() == 0);
break 'outer;
}

Data(NewTimer(timer)) => insert(timer, &mut active),
Ok(NewTimer(timer)) => insert(timer, &mut active),

Data(RemoveTimer(id, ack)) => {
Ok(RemoveTimer(id, ack)) => {
match dead.iter().position(|&(i, _)| id == i) {
Some(i) => {
let (_, i) = dead.remove(i).unwrap();
Expand Down
9 changes: 4 additions & 5 deletions src/libnative/io/timer_timerfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//!
//! As with timer_other, all units in this file are in units of millseconds.

use std::comm::Data;
use libc;
use std::ptr;
use std::os;
Expand Down Expand Up @@ -107,7 +106,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
match list.as_slice().bsearch(|&(f, _, _)| f.cmp(&fd)) {
Some(i) => {
let (_, ref c, oneshot) = *list.get(i);
(!c.try_send(()) || oneshot, i)
(c.send_opt(()).is_err() || oneshot, i)
}
None => fail!("fd not active: {}", fd),
}
Expand All @@ -121,7 +120,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {

while incoming {
match messages.try_recv() {
Data(NewTimer(fd, chan, one, timeval)) => {
Ok(NewTimer(fd, chan, one, timeval)) => {
// acknowledge we have the new channel, we will never send
// another message to the old channel
chan.send(());
Expand Down Expand Up @@ -149,7 +148,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
assert_eq!(ret, 0);
}

Data(RemoveTimer(fd, chan)) => {
Ok(RemoveTimer(fd, chan)) => {
match list.as_slice().bsearch(|&(f, _, _)| f.cmp(&fd)) {
Some(i) => {
drop(list.remove(i));
Expand All @@ -160,7 +159,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
chan.send(());
}

Data(Shutdown) => {
Ok(Shutdown) => {
assert!(list.len() == 0);
break 'outer;
}
Expand Down
9 changes: 4 additions & 5 deletions src/libnative/io/timer_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//! Other than that, the implementation is pretty straightforward in terms of
//! the other two implementations of timers with nothing *that* new showing up.

use std::comm::Data;
use libc;
use std::ptr;
use std::rt::rtio;
Expand Down Expand Up @@ -54,11 +53,11 @@ fn helper(input: libc::HANDLE, messages: Receiver<Req>) {
if idx == 0 {
loop {
match messages.try_recv() {
Data(NewTimer(obj, c, one)) => {
Ok(NewTimer(obj, c, one)) => {
objs.push(obj);
chans.push((c, one));
}
Data(RemoveTimer(obj, c)) => {
Ok(RemoveTimer(obj, c)) => {
c.send(());
match objs.iter().position(|&o| o == obj) {
Some(i) => {
Expand All @@ -68,7 +67,7 @@ fn helper(input: libc::HANDLE, messages: Receiver<Req>) {
None => {}
}
}
Data(Shutdown) => {
Ok(Shutdown) => {
assert_eq!(objs.len(), 1);
assert_eq!(chans.len(), 0);
break 'outer;
Expand All @@ -79,7 +78,7 @@ fn helper(input: libc::HANDLE, messages: Receiver<Req>) {
} else {
let remove = {
match chans.get(idx as uint - 1) {
&(ref c, oneshot) => !c.try_send(()) || oneshot
&(ref c, oneshot) => c.send_opt(()).is_err() || oneshot
}
};
if remove {
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ mod tests {
let _tx = tx;
fail!()
});
assert_eq!(rx.recv_opt(), None);
assert_eq!(rx.recv_opt(), Err(()));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/librustuv/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ mod test {
}
reads += 1;

tx2.try_send(());
let _ = tx2.send_opt(());
}

// Make sure we had multiple reads
Expand Down
2 changes: 1 addition & 1 deletion src/librustuv/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl SignalWatcher {
extern fn signal_cb(handle: *uvll::uv_signal_t, signum: c_int) {
let s: &mut SignalWatcher = unsafe { UvHandle::from_uv_handle(&handle) };
assert_eq!(signum as int, s.signal as int);
s.channel.try_send(s.signal);
let _ = s.channel.send_opt(s.signal);
}

impl HomingIO for SignalWatcher {
Expand Down
12 changes: 6 additions & 6 deletions src/librustuv/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ extern fn timer_cb(handle: *uvll::uv_timer_t, status: c_int) {
let task = timer.blocker.take_unwrap();
let _ = task.wake().map(|t| t.reawaken());
}
SendOnce(chan) => { let _ = chan.try_send(()); }
SendOnce(chan) => { let _ = chan.send_opt(()); }
SendMany(chan, id) => {
let _ = chan.try_send(());
let _ = chan.send_opt(());

// Note that the above operation could have performed some form of
// scheduling. This means that the timer may have decided to insert
Expand Down Expand Up @@ -196,8 +196,8 @@ mod test {
let oport = timer.oneshot(1);
let pport = timer.period(1);
timer.sleep(1);
assert_eq!(oport.recv_opt(), None);
assert_eq!(pport.recv_opt(), None);
assert_eq!(oport.recv_opt(), Err(()));
assert_eq!(pport.recv_opt(), Err(()));
timer.oneshot(1).recv();
}

Expand Down Expand Up @@ -284,7 +284,7 @@ mod test {
let mut timer = TimerWatcher::new(local_loop());
timer.oneshot(1000)
};
assert_eq!(port.recv_opt(), None);
assert_eq!(port.recv_opt(), Err(()));
}

#[test]
Expand All @@ -293,7 +293,7 @@ mod test {
let mut timer = TimerWatcher::new(local_loop());
timer.period(1000)
};
assert_eq!(port.recv_opt(), None);
assert_eq!(port.recv_opt(), Err(()));
}

#[test]
Expand Down
Loading