2012-07-05 23:14:27 -07:00
|
|
|
// xfail-pretty
|
2012-07-10 23:38:39 -07:00
|
|
|
// xfail-win32
|
2012-07-05 23:14:27 -07:00
|
|
|
|
2012-09-11 17:46:20 -07:00
|
|
|
extern mod std;
|
2012-09-05 12:32:05 -07:00
|
|
|
use std::timer::sleep;
|
|
|
|
use std::uv;
|
2012-07-03 17:33:20 -07:00
|
|
|
|
2012-09-05 12:32:05 -07:00
|
|
|
use pipes::{recv, select};
|
2012-07-03 17:33:20 -07:00
|
|
|
|
2012-08-22 18:10:48 -07:00
|
|
|
proto! oneshot (
|
2012-07-05 23:14:27 -07:00
|
|
|
waiting:send {
|
2012-07-16 14:44:27 -07:00
|
|
|
signal -> !
|
2012-07-03 17:33:20 -07:00
|
|
|
}
|
2012-08-22 18:10:48 -07:00
|
|
|
)
|
2012-07-03 17:33:20 -07:00
|
|
|
|
2012-08-22 18:10:48 -07:00
|
|
|
proto! stream (
|
2012-09-07 14:52:28 -07:00
|
|
|
stream:send<T:Send> {
|
2012-07-05 23:14:27 -07:00
|
|
|
send(T) -> stream<T>
|
2012-07-03 17:33:20 -07:00
|
|
|
}
|
2012-08-22 18:10:48 -07:00
|
|
|
)
|
2012-07-03 17:33:20 -07:00
|
|
|
|
|
|
|
fn main() {
|
2012-09-07 18:08:21 -07:00
|
|
|
use oneshot::client::*;
|
|
|
|
use stream::client::*;
|
2012-07-03 17:33:20 -07:00
|
|
|
|
|
|
|
let iotask = uv::global_loop::get();
|
|
|
|
|
|
|
|
let c = pipes::spawn_service(stream::init, |p| {
|
2012-08-22 17:24:52 -07:00
|
|
|
error!("waiting for pipes");
|
2012-09-18 22:45:24 -07:00
|
|
|
let stream::send(x, p) = recv(move p);
|
2012-08-22 17:24:52 -07:00
|
|
|
error!("got pipes");
|
2012-07-03 17:33:20 -07:00
|
|
|
let (left, right) : (oneshot::server::waiting,
|
|
|
|
oneshot::server::waiting)
|
2012-09-18 22:45:24 -07:00
|
|
|
= move x;
|
2012-08-22 17:24:52 -07:00
|
|
|
error!("selecting");
|
2012-09-18 22:45:24 -07:00
|
|
|
let (i, _, _) = select(~[move left, move right]);
|
2012-08-22 17:24:52 -07:00
|
|
|
error!("selected");
|
2012-07-03 17:33:20 -07:00
|
|
|
assert i == 0;
|
|
|
|
|
2012-08-22 17:24:52 -07:00
|
|
|
error!("waiting for pipes");
|
2012-09-18 22:45:24 -07:00
|
|
|
let stream::send(x, _) = recv(move p);
|
2012-08-22 17:24:52 -07:00
|
|
|
error!("got pipes");
|
2012-07-03 17:33:20 -07:00
|
|
|
let (left, right) : (oneshot::server::waiting,
|
|
|
|
oneshot::server::waiting)
|
2012-09-18 22:45:24 -07:00
|
|
|
= move x;
|
2012-08-22 17:24:52 -07:00
|
|
|
error!("selecting");
|
2012-09-18 22:45:24 -07:00
|
|
|
let (i, m, _) = select(~[move left, move right]);
|
2012-08-22 17:24:52 -07:00
|
|
|
error!("selected %?", i);
|
2012-09-07 18:53:14 -07:00
|
|
|
if m.is_some() {
|
2012-07-13 15:51:06 -07:00
|
|
|
assert i == 1;
|
|
|
|
}
|
2012-07-03 17:33:20 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
let (c1, p1) = oneshot::init();
|
2012-07-10 16:46:16 -07:00
|
|
|
let (_c2, p2) = oneshot::init();
|
2012-07-03 17:33:20 -07:00
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
let c = send(move c, (move p1, move p2));
|
2012-07-03 17:33:20 -07:00
|
|
|
|
2012-07-13 15:51:06 -07:00
|
|
|
sleep(iotask, 100);
|
2012-07-03 17:33:20 -07:00
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
signal(move c1);
|
2012-07-03 17:33:20 -07:00
|
|
|
|
2012-07-10 16:46:16 -07:00
|
|
|
let (_c1, p1) = oneshot::init();
|
2012-07-03 17:33:20 -07:00
|
|
|
let (c2, p2) = oneshot::init();
|
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
send(move c, (move p1, move p2));
|
2012-07-03 17:33:20 -07:00
|
|
|
|
2012-07-13 15:51:06 -07:00
|
|
|
sleep(iotask, 100);
|
2012-07-03 17:33:20 -07:00
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
signal(move c2);
|
2012-07-09 13:53:55 -07:00
|
|
|
|
|
|
|
test_select2();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_select2() {
|
|
|
|
let (ac, ap) = stream::init();
|
|
|
|
let (bc, bp) = stream::init();
|
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
stream::client::send(move ac, 42);
|
2012-07-09 13:53:55 -07:00
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
match pipes::select2(move ap, move bp) {
|
2012-08-14 16:54:13 -07:00
|
|
|
either::Left(*) => { }
|
|
|
|
either::Right(*) => { fail }
|
2012-07-09 13:53:55 -07:00
|
|
|
}
|
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
stream::client::send(move bc, ~"abc");
|
2012-07-09 13:53:55 -07:00
|
|
|
|
2012-08-22 17:24:52 -07:00
|
|
|
error!("done with first select2");
|
2012-07-09 13:53:55 -07:00
|
|
|
|
|
|
|
let (ac, ap) = stream::init();
|
|
|
|
let (bc, bp) = stream::init();
|
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
stream::client::send(move bc, ~"abc");
|
2012-07-09 13:53:55 -07:00
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
match pipes::select2(move ap, move bp) {
|
2012-08-14 16:54:13 -07:00
|
|
|
either::Left(*) => { fail }
|
|
|
|
either::Right(*) => { }
|
2012-07-09 13:53:55 -07:00
|
|
|
}
|
|
|
|
|
2012-09-18 22:45:24 -07:00
|
|
|
stream::client::send(move ac, 42);
|
2012-07-09 13:53:55 -07:00
|
|
|
}
|