mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-11 07:41:29 +03:00
Async (#30)
- manual eventloop now replaced by asycn-await using the tokio runtime - dns no longer blocks the event loop - simplifies logic - makes xdg-desktop-portal easier to integrate
This commit is contained in:
committed by
GitHub
parent
d4d6f05802
commit
ab2514e508
15
src/dns.rs
15
src/dns.rs
@@ -1,20 +1,23 @@
|
||||
use anyhow::Result;
|
||||
use std::{error::Error, net::IpAddr};
|
||||
|
||||
use trust_dns_resolver::Resolver;
|
||||
use trust_dns_resolver::TokioAsyncResolver;
|
||||
|
||||
pub(crate) struct DnsResolver {
|
||||
resolver: Resolver,
|
||||
resolver: TokioAsyncResolver,
|
||||
}
|
||||
impl DnsResolver {
|
||||
pub(crate) fn new() -> Result<Self> {
|
||||
let resolver = Resolver::from_system_conf()?;
|
||||
pub(crate) async fn new() -> Result<Self> {
|
||||
let resolver = TokioAsyncResolver::tokio_from_system_conf()?;
|
||||
Ok(Self { resolver })
|
||||
}
|
||||
|
||||
pub(crate) fn resolve(&self, host: &str) -> Result<Vec<IpAddr>, Box<dyn Error>> {
|
||||
pub(crate) async fn resolve(&self, host: &str) -> Result<Vec<IpAddr>, Box<dyn Error>> {
|
||||
log::info!("resolving {host} ...");
|
||||
let response = self.resolver.lookup_ip(host)?;
|
||||
let response = self.resolver.lookup_ip(host).await?;
|
||||
for ip in response.iter() {
|
||||
log::info!("{host}: adding ip {ip}");
|
||||
}
|
||||
Ok(response.iter().collect())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user