From 520f70bf8cb040b4f7267aba7e9b5ffdb68d5386 Mon Sep 17 00:00:00 2001 From: Tricster Date: Fri, 3 Feb 2023 17:26:44 +0800 Subject: [PATCH] Resolve DNS using tokio. Signed-off-by: Tricster --- Cargo.toml | 2 +- src/io/mod.rs | 31 +++++++++++-------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1fb4a41f..80dd03bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ url = "2.1" [target.'cfg(target_os="wasi")'.dependencies] tokio_wasi = {version = "1", features = [ "io-util", "fs", "net", "time", "rt", "macros", "sync"] } tokio-util_wasi = { version = "0.7.2", features = ["codec", "io"] } -wasmedge_wasi_socket = "0.4.2" +wasmedge_wasi_socket = "0.4.3" # [target.'cfg(not(target_os="wasi"))'.dev-dependencies] # tempfile = "3.1.0" diff --git a/src/io/mod.rs b/src/io/mod.rs index 5dadb985..28a09238 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -358,32 +358,23 @@ impl Stream { ) -> io::Result { let tcp_stream = match addr { HostPortOrUrl::HostPort(host, port) => { - #[cfg(target_os = "wasi")] - { - let mut addrs = wasmedge_wasi_socket::nslookup(host, "http").unwrap(); - for addr in addrs.iter_mut() { - addr.set_port(*port); - } - TcpStream::connect(&*addrs).await? - } - #[cfg(not(target_os = "wasi"))] TcpStream::connect((host.as_str(), *port)).await? } HostPortOrUrl::Url(url) => { #[cfg(not(target_os = "wasi"))] - let addrs = url.socket_addrs(|| Some(DEFAULT_PORT))?; - #[cfg(target_os = "wasi")] - let mut addrs = wasmedge_wasi_socket::nslookup( - url.host_str().expect("Unable to get host"), - "http", - ) - .unwrap(); - #[cfg(target_os = "wasi")] - for addr in addrs.iter_mut() { - addr.set_port(url.port_or_known_default().expect("No port found in url")); + { + let addrs = url.socket_addrs(|| Some(DEFAULT_PORT))?; + TcpStream::connect(addrs).await? } - TcpStream::connect(&*addrs).await? + #[cfg(target_os = "wasi")] + { + let addrs = ( + url.host_str().expect("Unable to get host"), + url.port_or_known_default().expect("No port found in url"), + ); + TcpStream::connect(addrs).await? + } } }; #[cfg(not(target_os = "wasi"))]