Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring: remove Send for DnsRecordBox #226

Merged
merged 1 commit into from
Jun 15, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/dns_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub const FLAGS_QR_QUERY: u16 = 0x0000;
pub const FLAGS_QR_RESPONSE: u16 = 0x8000;
pub const FLAGS_AA: u16 = 0x0400; // mask for Authoritative answer bit

pub type DnsRecordBox = Box<dyn DnsRecordExt + Send>;
pub type DnsRecordBox = Box<dyn DnsRecordExt>;

#[inline]
pub const fn ip_address_to_type(address: &IpAddr) -> u16 {
Expand Down Expand Up @@ -821,7 +821,7 @@ impl DnsOutgoing {
// server/responder SHOULD include the following additional records:

// o All address records (type "A" and "AAAA") named in the SRV rdata.
pub(crate) fn add_additional_answer(&mut self, answer: impl DnsRecordExt + Send + 'static) {
pub(crate) fn add_additional_answer(&mut self, answer: impl DnsRecordExt + 'static) {
debug!("add_additional_answer: {:?}", &answer);
self.additionals.push(Box::new(answer));
}
Expand Down
19 changes: 10 additions & 9 deletions src/service_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ impl ServiceDaemon {
.set_nonblocking(true)
.map_err(|e| e_fmt!("failed to set nonblocking for signal socket: {}", e))?;

let zc = Zeroconf::new(signal_sock)?;
let poller = Poller::new().map_err(|e| e_fmt!("Failed to create Poller: {}", e))?;

let (sender, receiver) = bounded(100);

// Spawn the daemon thread
thread::Builder::new()
.name("mDNS_daemon".to_string())
.spawn(move || Self::daemon_thread(zc, receiver))
.spawn(move || Self::daemon_thread(signal_sock, poller, receiver))
.map_err(|e| e_fmt!("thread builder failed to spawn: {}", e))?;

Ok(Self {
Expand Down Expand Up @@ -397,7 +398,9 @@ impl ServiceDaemon {
)))
}

fn daemon_thread(zc: Zeroconf, receiver: Receiver<Command>) {
fn daemon_thread(signal_sock: UdpSocket, poller: Poller, receiver: Receiver<Command>) {
let zc = Zeroconf::new(signal_sock, poller);

if let Some(cmd) = Self::run(zc, receiver) {
match cmd {
Command::Exit(resp_s) => {
Expand Down Expand Up @@ -908,9 +911,7 @@ struct Zeroconf {
}

impl Zeroconf {
fn new(signal_sock: UdpSocket) -> Result<Self> {
let poller = Poller::new().map_err(|e| e_fmt!("create Poller: {}", e))?;

fn new(signal_sock: UdpSocket, poller: Poller) -> Self {
// Get interfaces.
let my_ifaddrs = my_ip_interfaces();

Expand All @@ -937,7 +938,7 @@ impl Zeroconf {

let status = DaemonStatus::Running;

Ok(Self {
Self {
intf_socks,
poll_ids: HashMap::new(),
poll_id_count: 0,
Expand All @@ -955,7 +956,7 @@ impl Zeroconf {
timers,
status,
pending_resolves: HashSet::new(),
})
}
}

fn process_set_option(&mut self, daemon_opt: DaemonOption) {
Expand Down Expand Up @@ -1074,7 +1075,7 @@ impl Zeroconf {

if intf_selections[idx] {
// Add the interface
if self.intf_socks.get(&ip_addr).is_none() {
if !self.intf_socks.contains_key(&ip_addr) {
self.add_new_interface(intf);
}
} else {
Expand Down