forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebase on the new wasi-sockets. (bytecodealliance#91)
* Rebase on the new wasi-sockets. This switches to using the wasi-sockets wit files from WebAssembly/wasi-sockets#16. Many things are still stubbed out with `todo!()` for now. * Fix compilation on Windows.
- Loading branch information
1 parent
31cce7a
commit ea56fba
Showing
14 changed files
with
757 additions
and
747 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#![allow(unused_variables)] | ||
|
||
use crate::{ | ||
wasi_ip_name_lookup::{ResolveAddressStream, WasiIpNameLookup}, | ||
wasi_network::{Error, IpAddress, IpAddressFamily, Network}, | ||
wasi_poll::Pollable, | ||
HostResult, WasiCtx, | ||
}; | ||
|
||
#[async_trait::async_trait] | ||
impl WasiIpNameLookup for WasiCtx { | ||
async fn resolve_addresses( | ||
&mut self, | ||
network: Network, | ||
name: String, | ||
address_family: Option<IpAddressFamily>, | ||
include_unavailable: bool, | ||
) -> HostResult<ResolveAddressStream, Error> { | ||
todo!() | ||
} | ||
|
||
async fn resolve_next_address( | ||
&mut self, | ||
stream: ResolveAddressStream, | ||
) -> HostResult<Option<IpAddress>, Error> { | ||
todo!() | ||
} | ||
|
||
async fn drop_resolve_address_stream( | ||
&mut self, | ||
stream: ResolveAddressStream, | ||
) -> anyhow::Result<()> { | ||
todo!() | ||
} | ||
|
||
async fn non_blocking(&mut self, stream: ResolveAddressStream) -> HostResult<bool, Error> { | ||
todo!() | ||
} | ||
|
||
async fn set_non_blocking( | ||
&mut self, | ||
stream: ResolveAddressStream, | ||
value: bool, | ||
) -> HostResult<(), Error> { | ||
todo!() | ||
} | ||
|
||
async fn subscribe(&mut self, stream: ResolveAddressStream) -> anyhow::Result<Pollable> { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use crate::{ | ||
wasi_default_network::WasiDefaultNetwork, | ||
wasi_network::{Network, WasiNetwork}, | ||
WasiCtx, | ||
}; | ||
use crate::{ | ||
//wasi_network::{IpSocketAddress, Ipv4SocketAddress, Ipv6SocketAddress}, | ||
wasi_tcp, | ||
wasi_udp, | ||
}; | ||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; | ||
|
||
pub(crate) fn convert(_error: wasi_common::Error) -> anyhow::Error { | ||
todo!("convert wasi-common Error to wasi_network::Error") | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl WasiNetwork for WasiCtx { | ||
async fn drop_network(&mut self, _network: Network) -> anyhow::Result<()> { | ||
todo!() | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl WasiDefaultNetwork for WasiCtx { | ||
async fn default_network(&mut self) -> anyhow::Result<Network> { | ||
todo!() | ||
} | ||
} | ||
|
||
impl From<SocketAddr> for wasi_tcp::IpSocketAddress { | ||
fn from(addr: SocketAddr) -> Self { | ||
match addr { | ||
SocketAddr::V4(v4) => Self::Ipv4(v4.into()), | ||
SocketAddr::V6(v6) => Self::Ipv6(v6.into()), | ||
} | ||
} | ||
} | ||
|
||
impl From<SocketAddr> for wasi_udp::IpSocketAddress { | ||
fn from(addr: SocketAddr) -> Self { | ||
match addr { | ||
SocketAddr::V4(v4) => Self::Ipv4(v4.into()), | ||
SocketAddr::V6(v6) => Self::Ipv6(v6.into()), | ||
} | ||
} | ||
} | ||
|
||
impl From<SocketAddrV4> for wasi_tcp::Ipv4SocketAddress { | ||
fn from(addr: SocketAddrV4) -> Self { | ||
Self { | ||
address: MyIpv4Addr::from(addr.ip()).0, | ||
port: addr.port(), | ||
} | ||
} | ||
} | ||
|
||
impl From<SocketAddrV4> for wasi_udp::Ipv4SocketAddress { | ||
fn from(addr: SocketAddrV4) -> Self { | ||
Self { | ||
address: MyIpv4Addr::from(addr.ip()).0, | ||
port: addr.port(), | ||
} | ||
} | ||
} | ||
|
||
impl From<SocketAddrV6> for wasi_tcp::Ipv6SocketAddress { | ||
fn from(addr: SocketAddrV6) -> Self { | ||
Self { | ||
address: MyIpv6Addr::from(addr.ip()).0, | ||
port: addr.port(), | ||
flow_info: addr.flowinfo(), | ||
scope_id: addr.scope_id(), | ||
} | ||
} | ||
} | ||
|
||
impl From<SocketAddrV6> for wasi_udp::Ipv6SocketAddress { | ||
fn from(addr: SocketAddrV6) -> Self { | ||
Self { | ||
address: MyIpv6Addr::from(addr.ip()).0, | ||
port: addr.port(), | ||
flow_info: addr.flowinfo(), | ||
scope_id: addr.scope_id(), | ||
} | ||
} | ||
} | ||
|
||
// Newtypes to guide conversions. | ||
struct MyIpv4Addr((u8, u8, u8, u8)); | ||
struct MyIpv6Addr((u16, u16, u16, u16, u16, u16, u16, u16)); | ||
|
||
impl From<&Ipv4Addr> for MyIpv4Addr { | ||
fn from(addr: &Ipv4Addr) -> Self { | ||
let octets = addr.octets(); | ||
Self((octets[0], octets[1], octets[2], octets[3])) | ||
} | ||
} | ||
|
||
impl From<&Ipv6Addr> for MyIpv6Addr { | ||
fn from(addr: &Ipv6Addr) -> Self { | ||
let segments = addr.segments(); | ||
Self(( | ||
segments[0], | ||
segments[1], | ||
segments[2], | ||
segments[3], | ||
segments[4], | ||
segments[5], | ||
segments[6], | ||
segments[7], | ||
)) | ||
} | ||
} |
Oops, something went wrong.