Skip to content

Commit 667f5c7

Browse files
committed
Review comments & fixing CI
1 parent 8ecb16b commit 667f5c7

4 files changed

Lines changed: 47 additions & 5 deletions

File tree

crates/wasi/src/p2/bindings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ pub mod sync {
172172
"wasi:sockets/udp.incoming-datagram-stream": super::super::sockets::udp::IncomingDatagramStream,
173173
"wasi:sockets/udp.outgoing-datagram-stream": super::super::sockets::udp::OutgoingDatagramStream,
174174
"wasi:sockets/udp.udp-socket": crate::p2::UdpSocket,
175+
"wasi:sockets/ip-name-lookup.resolve-address-stream": crate::p2::ip_name_lookup::ResolveAddressStream,
175176

176177
// Error host trait from wasmtime-wasi-io is synchronous, so we can alias it
177178
"wasi:io/error": wasmtime_wasi_io::bindings::wasi::io::error,

crates/wasi/src/p2/host/udp.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,8 @@ impl udp::HostIncomingDatagramStream for WasiSocketsCtxView<'_> {
221221
&mut self,
222222
this: Resource<udp::IncomingDatagramStream>,
223223
) -> Result<(), wasmtime::Error> {
224-
// As in the filesystem implementation, we assume closing a socket
225-
// doesn't block.
226224
let dropped = self.table.delete(this)?;
227-
228225
dropped.finish().await;
229-
230226
Ok(())
231227
}
232228
}

crates/wasi/src/p2/ip_name_lookup.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,47 @@ impl Pollable for ResolveAddressStream {
7474
std::future::poll_fn(|cx| self.0.poll_ready(cx).map(|_| ())).await
7575
}
7676
}
77+
78+
mod sync {
79+
use super::ResolveAddressStream;
80+
use crate::p2::SocketError;
81+
use crate::p2::bindings::sockets::network::{IpAddress, Network};
82+
use crate::p2::bindings::sync::sockets::ip_name_lookup::{Host, HostResolveAddressStream};
83+
use crate::runtime::in_tokio;
84+
use crate::sockets::WasiSocketsCtxView;
85+
use wasmtime::Result;
86+
use wasmtime::component::Resource;
87+
use wasmtime_wasi_io::poll::DynPollable;
88+
89+
impl Host for WasiSocketsCtxView<'_> {
90+
fn resolve_addresses(
91+
&mut self,
92+
network: Resource<Network>,
93+
name: String,
94+
) -> Result<Resource<ResolveAddressStream>, SocketError> {
95+
<Self as super::Host>::resolve_addresses(self, network, name)
96+
}
97+
}
98+
99+
impl HostResolveAddressStream for WasiSocketsCtxView<'_> {
100+
fn resolve_next_address(
101+
&mut self,
102+
resource: Resource<ResolveAddressStream>,
103+
) -> Result<Option<IpAddress>, SocketError> {
104+
<Self as super::HostResolveAddressStream>::resolve_next_address(self, resource)
105+
}
106+
107+
fn subscribe(
108+
&mut self,
109+
resource: Resource<ResolveAddressStream>,
110+
) -> Result<Resource<DynPollable>> {
111+
<Self as super::HostResolveAddressStream>::subscribe(self, resource)
112+
}
113+
114+
fn drop(&mut self, resource: Resource<ResolveAddressStream>) -> Result<()> {
115+
in_tokio(<Self as super::HostResolveAddressStream>::drop(
116+
self, resource,
117+
))
118+
}
119+
}
120+
}

crates/wasi/src/p2/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ pub fn add_to_linker_with_options_async<T: WasiView>(
329329
bindings::sockets::tcp::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
330330
bindings::sockets::udp::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
331331
bindings::sockets::udp_create_socket::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
332+
bindings::sockets::ip_name_lookup::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
332333
Ok(())
333334
}
334335

@@ -362,7 +363,6 @@ where
362363
sockets::tcp_create_socket::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
363364
sockets::instance_network::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
364365
sockets::network::add_to_linker::<T, WasiSockets>(l, &options.into(), T::sockets)?;
365-
sockets::ip_name_lookup::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
366366
Ok(())
367367
}
368368

@@ -469,6 +469,7 @@ pub fn add_to_linker_with_options_sync<T: WasiView>(
469469
bindings::sync::sockets::tcp::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
470470
bindings::sync::sockets::udp::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
471471
bindings::sync::sockets::udp_create_socket::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
472+
bindings::sync::sockets::ip_name_lookup::add_to_linker::<T, WasiSockets>(l, T::sockets)?;
472473
Ok(())
473474
}
474475

0 commit comments

Comments
 (0)