Skip to content

Commit

Permalink
Resolve DNS using tokio.
Browse files Browse the repository at this point in the history
Signed-off-by: Tricster <[email protected]>
  • Loading branch information
MediosZ committed Feb 3, 2023
1 parent 11e5fb2 commit 520f70b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 11 additions & 20 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,32 +358,23 @@ impl Stream {
) -> io::Result<Stream> {
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"))]
Expand Down

0 comments on commit 520f70b

Please sign in to comment.