Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
//! ```
//!

#![forbid(unsafe_code)]
#![deny(unsafe_code)]
#![allow(clippy::single_component_path_imports)]

// log for logging (optional).
Expand Down
23 changes: 14 additions & 9 deletions src/service_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -482,10 +482,13 @@ impl ServiceDaemon {
/// 5. process retransmissions if any.
fn run(mut zc: Zeroconf, receiver: Receiver<Command>) -> Option<Command> {
// 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)]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! I want to keep this library safe code only, unless we really have to break it.

Let me take a look at our options.

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;
}
Expand All @@ -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;
}
Expand All @@ -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();

Expand Down Expand Up @@ -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;
}
Expand Down