From 9e96655757180d7fe32ebff1ed93a35a4c3cff28 Mon Sep 17 00:00:00 2001 From: kbleeke Date: Tue, 25 Apr 2023 19:08:47 +0200 Subject: [PATCH] comment some choices for current event handling --- src/control.rs | 6 ++++-- src/runner.rs | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/control.rs b/src/control.rs index 824c5512..0c06009b 100644 --- a/src/control.rs +++ b/src/control.rs @@ -197,18 +197,20 @@ impl<'a> Control<'a> { async fn wait_for_join(&mut self, i: SsidInfo) { self.events.mask.enable(&[Event::JOIN, Event::AUTH]); let mut subscriber = self.events.queue.subscriber().unwrap(); + // the actual join operation starts here + // we make sure to enable events before so we don't miss any self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) .await; // set_ssid loop { let msg = subscriber.next_message_pure().await; - if msg.header.event_type == Event::AUTH && msg.header.status != 0 { + if msg.header.event_type == Event::AUTH && msg.header.status != EStatus::SUCCESS { // retry warn!("JOIN failed with status={}", msg.header.status); self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) .await; - } else if msg.header.event_type == Event::JOIN && msg.header.status == 0 { + } else if msg.header.event_type == Event::JOIN && msg.header.status == EStatus::SUCCESS { // successful join break; } diff --git a/src/runner.rs b/src/runner.rs index 554a711d..806ddfc4 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -406,6 +406,10 @@ where let status = event_packet.msg.status; let event_payload = events::Payload::None; + // this intentionally uses the non-blocking publish immediate + // publish() is a deadlock risk in the current design as awaiting here prevents ioctls + // The `Runner` always yields when accessing the device, so consumers always have a chance to receive the event + // (if they are actively awaiting the queue) self.events.queue.publish_immediate(events::Message::new( Status { event_type: evt_type,