diff --git a/Cargo.toml b/Cargo.toml index 3fb5a7e..1bdc34c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,8 @@ default = ["async", "logging"] flume = { version = "0.11", default-features = false } # channel between threads if-addrs = { version = "0.10", features = ["link-local"] } # get local IP addresses log = { version = "0.4", optional = true } # logging -polling = "2.1" # select/poll sockets -socket2 = { version = "0.4", features = ["all"] } # socket APIs +polling = "3.4.0" # select/poll sockets +socket2 = { version = "0.5.5", features = ["all"] } # socket APIs [dev-dependencies] fastrand = "1.8" diff --git a/src/lib.rs b/src/lib.rs index 1039da5..c6a2fe5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,7 +107,6 @@ //! - Only support multicast, not unicast send/recv. //! - Only support 32-bit or bigger platforms, not 16-bit platforms. -#![forbid(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 89b2d5a..267b70b 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::Interface; -use polling::Poller; +use polling::{Events, Poller}; use socket2::{SockAddr, Socket}; use std::{ cmp, @@ -384,20 +384,24 @@ impl ServiceDaemon { fn run(mut zc: Zeroconf, receiver: Receiver) -> Option { // Add the daemon's signal socket to the poller. let signal_event_key = usize::MAX - 1; // avoid to overlap with zc.poll_ids - if let Err(e) = zc - .poller - .add(&zc.signal_sock, polling::Event::readable(signal_event_key)) - { - error!("failed to add signal socket to the poller: {}", e); - return None; + unsafe { + if let Err(e) = zc + .poller + .add(&zc.signal_sock, polling::Event::readable(signal_event_key)) + { + error!("failed to add signal socket to the poller: {}", e); + return None; + } } // Add mDNS sockets to the poller. for (ip, if_sock) in zc.intf_socks.iter() { let key = Zeroconf::add_poll_impl(&mut zc.poll_ids, &mut zc.poll_id_count, *ip); - if let Err(e) = zc.poller.add(&if_sock.sock, polling::Event::readable(key)) { - error!("add socket of {:?} to poller: {}", ip, e); - return None; + unsafe { + if let Err(e) = zc.poller.add(&if_sock.sock, polling::Event::readable(key)) { + error!("add socket of {:?} to poller: {}", ip, e); + return None; + } } } @@ -408,7 +412,7 @@ impl ServiceDaemon { // Start the run loop. - let mut events = Vec::new(); + let mut events = Events::new(); loop { let now = current_time_millis(); @@ -1135,9 +1139,11 @@ impl Zeroconf { // Add the new interface into the poller. let key = self.add_poll(new_ip); - if let Err(e) = self.poller.add(&sock, polling::Event::readable(key)) { - error!("check_ip_changes: poller add ip {}: {}", new_ip, e); - return; + unsafe { + if let Err(e) = self.poller.add(&sock, polling::Event::readable(key)) { + error!("check_ip_changes: poller add ip {}: {}", new_ip, e); + return; + } } self.intf_socks.insert(new_ip, IntfSock { intf, sock });