Skip to content

Commit 0506dd1

Browse files
authored
Merge pull request #171 from Berrysoft/dev/unix-resolve
feat(net): use spawn_blocking for unix resolver
2 parents 4f44a84 + 6835afe commit 0506dd1

File tree

2 files changed

+17
-53
lines changed

2 files changed

+17
-53
lines changed

compio-net/src/resolve/mod.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ cfg_if::cfg_if! {
55
} else if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
66
#[path = "glibc.rs"]
77
mod sys;
8-
} else if #[cfg(unix)] {
9-
#[path = "unix.rs"]
10-
mod sys;
118
}
129
}
1310

@@ -20,6 +17,7 @@ use std::{
2017
use compio_buf::{buf_try, BufResult};
2118
use either::Either;
2219

20+
#[cfg(any(windows, all(target_os = "linux", target_env = "gnu")))]
2321
pub async fn resolve_sock_addrs(
2422
host: &str,
2523
port: u16,
@@ -48,7 +46,7 @@ pub async fn resolve_sock_addrs(
4846
unsafe { resolver.addrs() }
4947
}
5048

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

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

78+
#[cfg(all(unix, not(all(target_os = "linux", target_env = "gnu"))))]
79+
pub async fn resolve_sock_addrs(
80+
host: &str,
81+
port: u16,
82+
) -> io::Result<std::vec::IntoIter<SocketAddr>> {
83+
use std::net::ToSocketAddrs;
84+
85+
use compio_runtime::Runtime;
86+
87+
let host = host.to_string();
88+
Runtime::current()
89+
.spawn_blocking(move || (host, port).to_socket_addrs())
90+
.await
91+
}
92+
8093
/// A trait for objects which can be converted or resolved to one or more
8194
/// [`SocketAddr`] values.
8295
///

compio-net/src/resolve/unix.rs

-49
This file was deleted.

0 commit comments

Comments
 (0)