From 6c5098e1427e28bf99ee483c7c2ccf62615751f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Sun, 1 Dec 2024 19:06:34 +0100 Subject: [PATCH] update polling to 3.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Grünbichler --- Cargo.toml | 2 +- src/lib.rs | 2 +- src/service_daemon.rs | 23 ++++++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1c87ecc1..7d448b84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ fastrand = "2.1" flume = { version = "0.11", default-features = false } # channel between threads if-addrs = { version = "0.13", features = ["link-local"] } # get local IP addresses log = { version = "0.4", optional = true } # logging -polling = "2.1" # select/poll sockets +polling = "3" # select/poll sockets socket2 = { version = "0.5.5", features = ["all"] } # socket APIs [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 1f7164ee..2ee6d7cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -128,7 +128,7 @@ //! ``` //! -#![forbid(unsafe_code)] +#![deny(unsafe_code)] #![allow(clippy::single_component_path_imports)] // log for logging (optional). diff --git a/src/service_daemon.rs b/src/service_daemon.rs index 3affa171..9ce7e163 100644 --- a/src/service_daemon.rs +++ b/src/service_daemon.rs @@ -43,7 +43,7 @@ use crate::{ }; use flume::{bounded, Sender, TrySendError}; use if_addrs::{IfAddr, Interface}; -use polling::Poller; +use polling::{Events, Poller}; use socket2::{SockAddr, Socket}; use std::{ cmp::{self, Reverse}, @@ -436,7 +436,7 @@ impl ServiceDaemon { } } - fn handle_poller_events(zc: &mut Zeroconf, events: &[polling::Event]) { + fn handle_poller_events(zc: &mut Zeroconf, events: &Events) { for ev in events.iter() { trace!("event received with key {}", ev.key); if ev.key == SIGNAL_SOCK_EVENT_KEY { @@ -482,10 +482,13 @@ impl ServiceDaemon { /// 5. process retransmissions if any. fn run(mut zc: Zeroconf, receiver: Receiver) -> Option { // Add the daemon's signal socket to the poller. - if let Err(e) = zc.poller.add( - &zc.signal_sock, - polling::Event::readable(SIGNAL_SOCK_EVENT_KEY), - ) { + #[allow(unsafe_code)] + if let Err(e) = unsafe { + zc.poller.add( + &zc.signal_sock, + polling::Event::readable(SIGNAL_SOCK_EVENT_KEY), + ) + } { debug!("failed to add signal socket to the poller: {}", e); return None; } @@ -494,7 +497,8 @@ impl ServiceDaemon { for (intf, sock) in zc.intf_socks.iter() { let key = Zeroconf::add_poll_impl(&mut zc.poll_ids, &mut zc.poll_id_count, intf.clone()); - if let Err(e) = zc.poller.add(sock, polling::Event::readable(key)) { + #[allow(unsafe_code)] + if let Err(e) = unsafe { zc.poller.add(sock, polling::Event::readable(key)) } { debug!("add socket of {:?} to poller: {}", intf, e); return None; } @@ -507,7 +511,7 @@ impl ServiceDaemon { // Start the run loop. - let mut events = Vec::new(); + let mut events = Events::new(); loop { let now = current_time_millis(); @@ -1149,7 +1153,8 @@ impl Zeroconf { // Add the new interface into the poller. let key = self.add_poll(intf.clone()); - if let Err(e) = self.poller.add(&sock, polling::Event::readable(key)) { + #[allow(unsafe_code)] + if let Err(e) = unsafe { self.poller.add(&sock, polling::Event::readable(key)) } { debug!("check_ip_changes: poller add ip {}: {}", new_ip, e); return; }