Skip to content

Commit

Permalink
Do not panic on incorrect client counts
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Feb 22, 2024
1 parent b3351b6 commit bdc3bca
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/board/wifi/ap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,17 @@ impl ApController {

pub fn handle_events(&mut self, events: EnumSet<WifiEvent>) -> bool {
if events.contains(WifiEvent::ApStaconnected) {
let old_count = self.state.client_count.fetch_add(1, Ordering::Release);
info!("Client connected, {} total", old_count + 1);
let old_count = self.state.client_count.load(Ordering::Release);
let new_count = old_count.saturating_add(1);
self.state.client_count.store(new_count, Ordering::Relaxed);
info!("Client connected, {} total", new_count);
}

if events.contains(WifiEvent::ApStadisconnected) {
let old_count = self.state.client_count.fetch_sub(1, Ordering::Release);
info!("Client disconnected, {} left", old_count - 1);
let old_count = self.state.client_count.load(Ordering::Release);
let new_count = old_count.saturating_sub(1);
self.state.client_count.store(new_count, Ordering::Relaxed);
info!("Client disconnected, {} left", new_count);
}

if events.contains(WifiEvent::ApStop) {
Expand Down

0 comments on commit bdc3bca

Please sign in to comment.