On 11/14/2013 04:03 PM, Diego Ongaro wrote:
Hi all,
My program starts a bunch of tasks, then I want the main task to both
receive ctrl-c signals and receive results from the children. The
signal will come from a std::rt::io::signal::Listener's port, which is
an std::comm::Port<Signum>. The child results will come from a
std::comm::Port<~[uint]>.
My first problem is that std::comm::Port doesn't implement
std::select::Select. It looks like std::rt::comm::Port does, and
std::comm::Port is just a small wrapper around that, but
std::comm::Port makes its internal std::rt::comm::Port private. Is
there any way to select on a std::comm::Port? (And what's the
difference between a std::rt::comm::Port and a std::comm::Port?)
There currently isn't a way - this feature isn't fully baked yet, but it
should not take a whole lot of effort to get it working. There is no
functional difference between std::comm and std::rt::comm;
std::rt::comm should be moved wholesale to std::comm and the current
std::comm deleted, but it hasn't been done yet.
My second problem is that std::select::select() doesn't seem to
support selecting from ports with different types. Naively, I tried
select([p1, p2]), but that expects p1 and p2 to have the same type:
error: mismatched types: expected
`std::rt::comm::Port<std::rt::io::signal::Signum>` but found
`std::rt::comm::Port<~[uint]>` (expected enum
std::rt::io::signal::Signum but found vector)
It'll need dynamic dispatch, so I tried: select([p1 as &Select, p2 as
&Select]). However, this doesn't work since &Select doesn't implement
Select:
error: failed to find an implementation of trait std::select::Select
for &std::select::Select<no-bounds>
There's some commented out code that may be related in select.rs,
though it's hard for me to know where this stands:
/* FIXME(#5121, #7914) This all should be legal, but rust is not
clever enough yet.
impl <'self> Select for &'self mut Select {
fn optimistic_check(&mut self) -> bool { self.optimistic_check() }
fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) -> bool {
self.block_on(sched, task)
}
fn unblock_from(&mut self) -> bool { self.unblock_from() }
}
...
How can I select on two ports of different types?
My understanding is that this code needs to be enabled to make select on
heterogenous types work correctly. I do not know the details of this
code but it appears that Niko has not landed a fix for #5121 yet.
Contributions here are very welcome.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev