From bd98f13f67891950bb0dc6ecd21a8aba14aeac55 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Sun, 13 Mar 2022 20:38:11 +0100 Subject: [PATCH] Simplify Actor impl to have a static source --- bffhd/actors/mod.rs | 37 +++++++------------------------------ bffhd/lib.rs | 2 +- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/bffhd/actors/mod.rs b/bffhd/actors/mod.rs index 1289c37..a0323a9 100644 --- a/bffhd/actors/mod.rs +++ b/bffhd/actors/mod.rs @@ -17,8 +17,7 @@ fn loader>(cell: &Cell>) -> Option { } pub struct ActorDriver { - rx: MutableSignalRef>, &'static dyn Fn(&Cell>) -> Option>, - signal: Option, + signal: S, actor: Box, future: Option>, @@ -26,14 +25,11 @@ pub struct ActorDriver { impl> ActorDriver { - pub fn new(rx: &ReadOnlyMutable>>, actor: Box) + pub fn new(signal: S, actor: Box) -> Self { - let f: &'static dyn Fn(&Cell>) -> Option = &loader; - let rx = rx.signal_ref(f); Self { - rx, - signal: None, + signal, actor, future: None, } @@ -47,14 +43,6 @@ impl Future for ActorDriver type Output = (); fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll { - let mut done = false; // Is the channel with new state-signals exhausted? - - match Pin::new(&mut self.rx).poll_change(cx) { - Poll::Ready(Some(new_signal)) => { self.signal = new_signal; }, - Poll::Ready(None) => done = true, - Poll::Pending => {}, - } - // Work until there is no more work to do. loop { @@ -73,22 +61,11 @@ impl Future for ActorDriver } // Poll the signal and apply any change that happen to the inner Actuator - match self.signal.as_mut() - .map(|inner| S::poll_change(Pin::new(inner), cx)) + match Pin::new(&mut self.signal).poll_change(cx) { - // No signal to poll - None => return Poll::Pending, - Some(Poll::Pending) => return Poll::Pending, - Some(Poll::Ready(None)) => { - self.signal = None; - - if done { - return Poll::Ready(()); - } else { - return Poll::Pending; - } - }, - Some(Poll::Ready(Some(state))) => { + Poll::Pending => return Poll::Pending, + Poll::Ready(None) => return Poll::Pending, + Poll::Ready(Some(state)) => { // This future MUST be polled before we exit from the Actor::poll because if we // do not do that it will not register the dependency and thus NOT BE POLLED. let f = self.actor.apply(state); diff --git a/bffhd/lib.rs b/bffhd/lib.rs index 0e10d84..27fd686 100644 --- a/bffhd/lib.rs +++ b/bffhd/lib.rs @@ -100,7 +100,7 @@ impl Diflouroborane { Resource::new(Arc::new(resources::Inner::new(id.to_string(), statedb.clone(), desc.clone()))) })); RESOURCES.set(resources); - // - Connect modules to machines + let tlsconfig = TlsConfig::new(config.tlskeylog.as_ref(), !config.is_quiet())?; let acceptor = tlsconfig.make_tls_acceptor(&config.tlsconfig)?;