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/0.5.4 #91

Merged
merged 4 commits into from
Feb 26, 2024
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
84 changes: 0 additions & 84 deletions .github/workflows/example_0.11.yml

This file was deleted.

84 changes: 0 additions & 84 deletions .github/workflows/example_0.12.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: examples 0.10
name: examples 0.13

on:
workflow_dispatch:
Expand Down Expand Up @@ -30,7 +30,7 @@ jobs:
rustup target add wasm32-wasi
- name: Install WasmEdge
run: |
VERSION=0.10.0
VERSION=0.13.5
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | sudo bash -s -- -e all --version=$VERSION --tf-version=$VERSION --tf-deps-version=$VERSION --tf-tools-version=$VERSION --image-version=$VERSION -p /usr/local

# Disable this example due to it relies on wasmedge_http_req, which is a cyclic dependence
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:

- name: UDP Socket Example
run: |
cargo build --target wasm32-wasi --example=udp_socket --release --no-default-features --features=built-in-dns
cargo build --target wasm32-wasi --example=udp_socket --release
wasmedge target/wasm32-wasi/release/examples/udp_socket.wasm

- name: DNS Example
Expand Down
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasmedge_wasi_socket"
version = "0.5.3"
version = "0.5.4"
authors = ["Yi <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand All @@ -21,8 +21,6 @@ libc = "0.2.3"
rand = "0.8.5"

[features]
default = ["wasmedge_0_12"]
wasmedge_0_12 = []
built-in-dns = []
default = []
wasi_poll = []
epoll = []
20 changes: 15 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,16 @@ impl AsRawFd for UdpSocket {
}
}

#[cfg(not(feature = "built-in-dns"))]
pub fn nslookup(node: &str, service: &str) -> std::io::Result<Vec<SocketAddr>> {
let dns_server = std::env::var("DNS_SERVER");
if let Ok(dns_server) = dns_server {
nslookup_with_dns_server(&dns_server, node, service)
} else {
nslookup_with_host(node, service)
}
}

pub fn nslookup_with_host(node: &str, service: &str) -> std::io::Result<Vec<SocketAddr>> {
use socket::WasiAddrinfo;
let hints: WasiAddrinfo = WasiAddrinfo::default();
let mut sockaddrs = Vec::new();
Expand Down Expand Up @@ -367,11 +375,13 @@ pub fn nslookup(node: &str, service: &str) -> std::io::Result<Vec<SocketAddr>> {
Ok(r_addrs)
}

#[cfg(feature = "built-in-dns")]
pub fn nslookup(node: &str, _service: &str) -> std::io::Result<Vec<SocketAddr>> {
let dns_server = std::env::var("DNS_SERVER").unwrap_or("8.8.8.8:53".into());
pub fn nslookup_with_dns_server(
dns_server: &str,
node: &str,
_service: &str,
) -> std::io::Result<Vec<SocketAddr>> {
let mut conn = TcpStream::connect(dns_server)?;
let timeout = std::time::Duration::from_secs(1);
let timeout = std::time::Duration::from_secs(5);
let _ignore = conn.as_mut().set_send_timeout(Some(timeout));
let _ignore = conn.as_mut().set_recv_timeout(Some(timeout));

Expand Down
Loading
Loading