forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasi: enable TcpListener and TcpStream
With the addition of `sock_accept()` to snapshot1, simple networking via a passed `TcpListener` is possible. This patch implements the basics to make a simple server work. Signed-off-by: Harald Hoyer <harald@profian.com>
- Loading branch information
Showing
3 changed files
with
77 additions
and
13 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 |
---|---|---|
@@ -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) | ||
} | ||
} |
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