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

feat(net): use spawn_blocking for unix resolver #171

Merged
merged 1 commit into from
Dec 11, 2023
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
21 changes: 17 additions & 4 deletions compio-net/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ cfg_if::cfg_if! {
} else if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
#[path = "glibc.rs"]
mod sys;
} else if #[cfg(unix)] {
#[path = "unix.rs"]
mod sys;
}
}

Expand All @@ -20,6 +17,7 @@ use std::{
use compio_buf::{buf_try, BufResult};
use either::Either;

#[cfg(any(windows, all(target_os = "linux", target_env = "gnu")))]
pub async fn resolve_sock_addrs(
host: &str,
port: u16,
Expand Down Expand Up @@ -48,7 +46,7 @@ pub async fn resolve_sock_addrs(
unsafe { resolver.addrs() }
}

#[allow(dead_code)]
#[cfg(any(windows, all(target_os = "linux", target_env = "gnu")))]
fn to_addrs(mut result: *mut sys::addrinfo, port: u16) -> std::vec::IntoIter<SocketAddr> {
use socket2::SockAddr;

Expand Down Expand Up @@ -77,6 +75,21 @@ fn to_addrs(mut result: *mut sys::addrinfo, port: u16) -> std::vec::IntoIter<Soc
addrs.into_iter()
}

#[cfg(all(unix, not(all(target_os = "linux", target_env = "gnu"))))]
pub async fn resolve_sock_addrs(
host: &str,
port: u16,
) -> io::Result<std::vec::IntoIter<SocketAddr>> {
use std::net::ToSocketAddrs;

use compio_runtime::Runtime;

let host = host.to_string();
Runtime::current()
.spawn_blocking(move || (host, port).to_socket_addrs())
.await
}

/// A trait for objects which can be converted or resolved to one or more
/// [`SocketAddr`] values.
///
Expand Down
49 changes: 0 additions & 49 deletions compio-net/src/resolve/unix.rs

This file was deleted.