Skip to content

Commit

Permalink
Bump polling and socket2 version
Browse files Browse the repository at this point in the history
  • Loading branch information
irvingoujAtDevolution committed Feb 13, 2024
1 parent 4d719a3 commit fe566e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
34 changes: 20 additions & 14 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::Interface;
use polling::Poller;
use polling::{Events, Poller};
use socket2::{SockAddr, Socket};
use std::{
cmp,
Expand Down Expand Up @@ -384,20 +384,24 @@ impl ServiceDaemon {
fn run(mut zc: Zeroconf, receiver: Receiver<Command>) -> Option<Command> {
// 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;
}
}
}

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

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

0 comments on commit fe566e8

Please sign in to comment.