2012-07-13 16:05:28 -05:00
|
|
|
// xfail-test
|
2012-07-06 01:14:27 -05:00
|
|
|
// xfail-pretty
|
2012-07-11 01:38:39 -05:00
|
|
|
// xfail-win32
|
2012-07-06 01:14:27 -05:00
|
|
|
|
2012-07-03 19:33:20 -05:00
|
|
|
use std;
|
|
|
|
import std::timer::sleep;
|
|
|
|
import std::uv;
|
|
|
|
|
|
|
|
import pipes::{recv, select};
|
|
|
|
|
2012-07-06 01:14:27 -05:00
|
|
|
proto! oneshot {
|
|
|
|
waiting:send {
|
|
|
|
signal -> signaled
|
2012-07-03 19:33:20 -05:00
|
|
|
}
|
2012-07-06 01:14:27 -05:00
|
|
|
|
|
|
|
signaled:send { }
|
2012-07-03 19:33:20 -05:00
|
|
|
}
|
|
|
|
|
2012-07-06 01:14:27 -05:00
|
|
|
proto! stream {
|
|
|
|
stream:send<T:send> {
|
|
|
|
send(T) -> stream<T>
|
2012-07-03 19:33:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
import oneshot::client::*;
|
|
|
|
import stream::client::*;
|
|
|
|
|
|
|
|
let iotask = uv::global_loop::get();
|
|
|
|
|
|
|
|
let c = pipes::spawn_service(stream::init, |p| {
|
|
|
|
#error("waiting for pipes");
|
2012-07-10 13:40:03 -05:00
|
|
|
let stream::send(x, p) = recv(p);
|
2012-07-03 19:33:20 -05:00
|
|
|
#error("got pipes");
|
|
|
|
let (left, right) : (oneshot::server::waiting,
|
|
|
|
oneshot::server::waiting)
|
|
|
|
= x;
|
|
|
|
#error("selecting");
|
|
|
|
let (i, _, _) = select(~[left, right]);
|
|
|
|
#error("selected");
|
|
|
|
assert i == 0;
|
|
|
|
|
|
|
|
#error("waiting for pipes");
|
2012-07-10 13:40:03 -05:00
|
|
|
let stream::send(x, _) = recv(p);
|
2012-07-03 19:33:20 -05:00
|
|
|
#error("got pipes");
|
|
|
|
let (left, right) : (oneshot::server::waiting,
|
|
|
|
oneshot::server::waiting)
|
|
|
|
= x;
|
|
|
|
#error("selecting");
|
2012-07-13 17:51:06 -05:00
|
|
|
let (i, m, _) = select(~[left, right]);
|
|
|
|
#error("selected %?", i);
|
|
|
|
if m != none {
|
|
|
|
assert i == 1;
|
|
|
|
}
|
2012-07-03 19:33:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
let (c1, p1) = oneshot::init();
|
2012-07-10 18:46:16 -05:00
|
|
|
let (_c2, p2) = oneshot::init();
|
2012-07-03 19:33:20 -05:00
|
|
|
|
|
|
|
let c = send(c, (p1, p2));
|
|
|
|
|
2012-07-13 17:51:06 -05:00
|
|
|
sleep(iotask, 100);
|
2012-07-03 19:33:20 -05:00
|
|
|
|
|
|
|
signal(c1);
|
|
|
|
|
2012-07-10 18:46:16 -05:00
|
|
|
let (_c1, p1) = oneshot::init();
|
2012-07-03 19:33:20 -05:00
|
|
|
let (c2, p2) = oneshot::init();
|
|
|
|
|
|
|
|
send(c, (p1, p2));
|
|
|
|
|
2012-07-13 17:51:06 -05:00
|
|
|
sleep(iotask, 100);
|
2012-07-03 19:33:20 -05:00
|
|
|
|
|
|
|
signal(c2);
|
2012-07-09 15:53:55 -05:00
|
|
|
|
|
|
|
test_select2();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_select2() {
|
|
|
|
let (ac, ap) = stream::init();
|
|
|
|
let (bc, bp) = stream::init();
|
|
|
|
|
|
|
|
stream::client::send(ac, 42);
|
|
|
|
|
|
|
|
alt pipes::select2(ap, bp) {
|
|
|
|
either::left(*) { }
|
|
|
|
either::right(*) { fail }
|
|
|
|
}
|
|
|
|
|
|
|
|
stream::client::send(bc, "abc");
|
|
|
|
|
|
|
|
#error("done with first select2");
|
|
|
|
|
|
|
|
let (ac, ap) = stream::init();
|
|
|
|
let (bc, bp) = stream::init();
|
|
|
|
|
|
|
|
stream::client::send(bc, "abc");
|
|
|
|
|
|
|
|
alt pipes::select2(ap, bp) {
|
|
|
|
either::left(*) { fail }
|
|
|
|
either::right(*) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
stream::client::send(ac, 42);
|
|
|
|
}
|