-
Notifications
You must be signed in to change notification settings - Fork 13k
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
wasi: implement sock_accept
and enable networking
#93158
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
//! WASI-specific networking functionality | ||
|
||
#![unstable(feature = "wasi_ext", issue = "71213")] | ||
|
||
use crate::io; | ||
use crate::net; | ||
use crate::sys_common::AsInner; | ||
|
||
/// WASI-specific extensions to [`std::net::TcpListener`]. | ||
/// | ||
/// [`std::net::TcpListener`]: crate::net::TcpListener | ||
pub trait TcpListenerExt { | ||
/// Accept a socket. | ||
/// | ||
/// This corresponds to the `sock_accept` syscall. | ||
fn sock_accept(&self, flags: u16) -> io::Result<u32>; | ||
} | ||
|
||
impl TcpListenerExt for net::TcpListener { | ||
fn sock_accept(&self, flags: u16) -> io::Result<u32> { | ||
self.as_inner().as_inner().as_inner().sock_accept(flags) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -61,23 +61,26 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { | |||
if errno > u16::MAX as i32 || errno < 0 { | ||||
return Uncategorized; | ||||
} | ||||
match errno as u16 { | ||||
wasi::ERRNO_CONNREFUSED => ConnectionRefused, | ||||
wasi::ERRNO_CONNRESET => ConnectionReset, | ||||
wasi::ERRNO_PERM | wasi::ERRNO_ACCES => PermissionDenied, | ||||
wasi::ERRNO_PIPE => BrokenPipe, | ||||
wasi::ERRNO_NOTCONN => NotConnected, | ||||
wasi::ERRNO_CONNABORTED => ConnectionAborted, | ||||
wasi::ERRNO_ADDRNOTAVAIL => AddrNotAvailable, | ||||
wasi::ERRNO_ADDRINUSE => AddrInUse, | ||||
wasi::ERRNO_NOENT => NotFound, | ||||
wasi::ERRNO_INTR => Interrupted, | ||||
wasi::ERRNO_INVAL => InvalidInput, | ||||
wasi::ERRNO_TIMEDOUT => TimedOut, | ||||
wasi::ERRNO_EXIST => AlreadyExists, | ||||
wasi::ERRNO_AGAIN => WouldBlock, | ||||
wasi::ERRNO_NOSYS => Unsupported, | ||||
wasi::ERRNO_NOMEM => OutOfMemory, | ||||
|
||||
match errno { | ||||
e if e == wasi::ERRNO_CONNREFUSED.raw().into() => ConnectionRefused, | ||||
e if e == wasi::ERRNO_CONNRESET.raw().into() => ConnectionReset, | ||||
e if e == wasi::ERRNO_PERM.raw().into() || e == wasi::ERRNO_ACCES.raw().into() => { | ||||
PermissionDenied | ||||
} | ||||
e if e == wasi::ERRNO_PIPE.raw().into() => BrokenPipe, | ||||
e if e == wasi::ERRNO_NOTCONN.raw().into() => NotConnected, | ||||
e if e == wasi::ERRNO_CONNABORTED.raw().into() => ConnectionAborted, | ||||
e if e == wasi::ERRNO_ADDRNOTAVAIL.raw().into() => AddrNotAvailable, | ||||
e if e == wasi::ERRNO_ADDRINUSE.raw().into() => AddrInUse, | ||||
e if e == wasi::ERRNO_NOENT.raw().into() => NotFound, | ||||
e if e == wasi::ERRNO_INTR.raw().into() => Interrupted, | ||||
e if e == wasi::ERRNO_INVAL.raw().into() => InvalidInput, | ||||
e if e == wasi::ERRNO_TIMEDOUT.raw().into() => TimedOut, | ||||
e if e == wasi::ERRNO_EXIST.raw().into() => AlreadyExists, | ||||
e if e == wasi::ERRNO_AGAIN.raw().into() => WouldBlock, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 66 has this already.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||||
e if e == wasi::ERRNO_NOSYS.raw().into() => Unsupported, | ||||
e if e == wasi::ERRNO_NOMEM.raw().into() => OutOfMemory, | ||||
_ => Uncategorized, | ||||
} | ||||
} | ||||
|
@@ -96,6 +99,6 @@ pub fn hashmap_random_keys() -> (u64, u64) { | |||
return ret; | ||||
} | ||||
|
||||
fn err2io(err: wasi::Error) -> std_io::Error { | ||||
std_io::Error::from_raw_os_error(err.raw_error().into()) | ||||
fn err2io(err: wasi::Errno) -> std_io::Error { | ||||
std_io::Error::from_raw_os_error(err.raw().into()) | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe