summaryrefslogtreecommitdiff
path: root/src/eventloop.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/eventloop.rs')
-rw-r--r--src/eventloop.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/eventloop.rs b/src/eventloop.rs
index 2cf8ecd..84f1e77 100644
--- a/src/eventloop.rs
+++ b/src/eventloop.rs
@@ -66,7 +66,6 @@ impl<'a> Context<'a> {
slab_insert(&mut self.parent.tokens, self.machine)
}
- #[allow(dead_code)]
pub fn unassign(&mut self, t: Token) {
assert_eq!(self.parent.tokens[t], self.machine);
self.parent.tokens.remove(t);
@@ -78,22 +77,22 @@ impl<'a> Context<'a> {
self.parent.poll.register(io, token, interest, mio::PollOpt::level()).unwrap();
}
- #[allow(dead_code)]
pub fn reregister<E: ?Sized>(&mut self, io: &E, token: Token, interest: mio::Ready) where E: mio::Evented {
self.parent.poll.reregister(io, token, interest, mio::PollOpt::level()).unwrap();
}
- #[allow(dead_code)]
pub fn deregister<E: ?Sized>(&mut self, io: &E) where E: mio::Evented {
self.parent.poll.deregister(io).unwrap();
}
- #[allow(dead_code)]
pub fn remove(&mut self) {
self.removed = true;
}
- #[allow(dead_code)]
+ pub fn is_removed(&self) -> bool {
+ self.removed
+ }
+
pub fn spawn(&mut self, machine: Box<Machine>) {
self.parent.spawn(machine);
}
@@ -111,6 +110,7 @@ impl EventLoop {
pub fn spawn(&mut self, mut machine: Box<Machine>) {
let mtoken = slab_insert(&mut self.machines, None);
+ trace!("Spawning machine {}", mtoken.0);
{
let mut ctx = Context{ parent: self, machine: mtoken, removed: false };
machine.init(&mut ctx);
@@ -124,11 +124,11 @@ impl EventLoop {
debug!("Entering event loop");
loop {
self.poll.poll(&mut events, None).unwrap();
- trace!("Poll returned with {} events", events.len());
for event in events.iter() {
let mtoken = self.tokens[event.token()];
- let mut machine = self.machines.entry(mtoken).unwrap().replace(None).unwrap();
+ trace!("Poll returned event {} on machine {} state {:?}", event.token().0, mtoken.0, event.kind());
+ let mut machine = self.machines.entry(mtoken).unwrap().replace(None).unwrap();
let removed = {
let mut ctx = Context{ parent: self, machine: mtoken, removed: false };
machine.handle(&mut ctx, event);
@@ -137,6 +137,8 @@ impl EventLoop {
if !removed {
self.machines[mtoken] = Some(machine);
+ } else {
+ trace!("Removing machine {}", mtoken.0);
}
}
}