Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Add basic TCP socket APIs.
Browse files Browse the repository at this point in the history
This is based on @npmccullum's [wasi-snapshot-preview2 draft] which is
in turn based on the [wasi-sockets proposal], though for simplify for
now it omits UDP sockets and some other features.

It's also based on the [pseudo-streams PR]; so that should proceed
first before this.

[draft wasi-snapshot-preview2]: https://github.com/npmccallum/wasi-snapshot-preview2
[wasi-sockets proposal]: https://github.com/WebAssembly/wasi-sockets
[pseudo-streams PR]: #29
  • Loading branch information
sunfishcode committed Jan 30, 2023
1 parent 6ff8e85 commit c3e8de0
Show file tree
Hide file tree
Showing 17 changed files with 809 additions and 225 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 8 additions & 33 deletions host/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use wasi_common::{
WasiDir, WasiFile,
};

// FIXME: guest rust bindgen should add this method to all flags.
/// TODO: Remove once wasmtime #5589 lands.
fn contains<T: BitAnd<Output = T> + Eq + Copy>(flags: T, flag: T) -> bool {
(flags & flag) == flag
}
Expand All @@ -26,53 +26,28 @@ fn convert(error: wasi_common::Error) -> anyhow::Error {

match errno {
Acces => Errno::Access,
Addrinuse => Errno::Addrinuse,
Addrnotavail => Errno::Addrnotavail,
Afnosupport => Errno::Afnosupport,
Again => Errno::Again,
Already => Errno::Already,
Badf => Errno::Badf,
Badmsg => Errno::Badmsg,
Busy => Errno::Busy,
Canceled => Errno::Canceled,
Child => Errno::Child,
Connaborted => Errno::Connaborted,
Connrefused => Errno::Connrefused,
Connreset => Errno::Connreset,
Deadlk => Errno::Deadlk,
Destaddrreq => Errno::Destaddrreq,
Dquot => Errno::Dquot,
Exist => Errno::Exist,
Fault => Errno::Fault,
Fbig => Errno::Fbig,
Hostunreach => Errno::Hostunreach,
Idrm => Errno::Idrm,
Ilseq => Errno::Ilseq,
Inprogress => Errno::Inprogress,
Intr => Errno::Intr,
Inval => Errno::Inval,
Io => Errno::Io,
Isconn => Errno::Isconn,
Isdir => Errno::Isdir,
Loop => Errno::Loop,
Mfile => Errno::Mfile,
Mlink => Errno::Mlink,
Msgsize => Errno::Msgsize,
Multihop => Errno::Multihop,
Nametoolong => Errno::Nametoolong,
Netdown => Errno::Netdown,
Netreset => Errno::Netreset,
Netunreach => Errno::Netunreach,
Nfile => Errno::Nfile,
Nobufs => Errno::Nobufs,
Nodev => Errno::Nodev,
Noent => Errno::Noent,
Noexec => Errno::Noexec,
Nolck => Errno::Nolck,
Nolink => Errno::Nolink,
Nomem => Errno::Nomem,
Nomsg => Errno::Nomsg,
Noprotoopt => Errno::Noprotoopt,
Nospc => Errno::Nospc,
Nosys => Errno::Nosys,
Notdir => Errno::Notdir,
Expand All @@ -82,21 +57,21 @@ fn convert(error: wasi_common::Error) -> anyhow::Error {
Notty => Errno::Notty,
Nxio => Errno::Nxio,
Overflow => Errno::Overflow,
Ownerdead => Errno::Ownerdead,
Perm => Errno::Perm,
Pipe => Errno::Pipe,
Range => Errno::Range,
Rofs => Errno::Rofs,
Spipe => Errno::Spipe,
Srch => Errno::Srch,
Stale => Errno::Stale,
Timedout => Errno::Timedout,
Txtbsy => Errno::Txtbsy,
Xdev => Errno::Xdev,
Success | Dom | Notcapable | Notsock | Proto | Protonosupport | Prototype | TooBig
| Notconn => {
Success | Notsock | Proto | Protonosupport | Prototype | TooBig | Notconn => {
return error.into();
}
Addrinuse | Addrnotavail | Afnosupport | Badmsg | Canceled | Connaborted
| Connrefused | Connreset | Destaddrreq | Fault | Hostunreach | Idrm | Isconn
| Mfile | Multihop | Netdown | Netreset | Netunreach | Nfile | Nobufs | Noexec
| Nolink | Nomsg | Noprotoopt | Ownerdead | Range | Srch | Stale | Timedout => {
panic!("Unexpected errno: {:?}", errno);
}
}
.into()
} else {
Expand Down
Loading

0 comments on commit c3e8de0

Please sign in to comment.