-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Harald Hoyer <harald@profian.com>
- Loading branch information
Showing
20 changed files
with
491 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Submodule WASI
updated
5 files
+7 −1 | docs/Proposals.md | |
+2 −2 | docs/witx.md | |
+32 −0 | phases/snapshot/docs.md | |
+2 −0 | phases/snapshot/witx/typenames.witx | |
+11 −0 | phases/snapshot/witx/wasi_snapshot_preview1.witx |
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
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
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
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,156 @@ | ||
use super::tcpstream::TcpStream; | ||
use std::any::Any; | ||
use std::io; | ||
use wasi_common::{ | ||
file::{Advice, FdFlags, FileType, Filestat, WasiFile}, | ||
Error, ErrorExt, | ||
}; | ||
|
||
pub struct TcpListener(cap_std::net::TcpListener); | ||
|
||
impl TcpListener { | ||
pub fn from_cap_std(socket: cap_std::net::TcpListener) -> Self { | ||
TcpListener(socket) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl WasiFile for TcpListener { | ||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
async fn sock_accept(&mut self, fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> { | ||
let (stream, _) = self.0.accept()?; | ||
let mut stream = TcpStream::from_cap_std(stream); | ||
stream.set_fdflags(fdflags).await?; | ||
Ok(Box::new(stream)) | ||
} | ||
async fn datasync(&self) -> Result<(), Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn sync(&self) -> Result<(), Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn get_filetype(&self) -> Result<FileType, Error> { | ||
Ok(FileType::SocketStream) | ||
} | ||
async fn get_fdflags(&self) -> Result<FdFlags, Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn set_fdflags(&mut self, fdflags: FdFlags) -> Result<(), Error> { | ||
if fdflags == wasi_common::file::FdFlags::NONBLOCK { | ||
self.0.set_nonblocking(true)?; | ||
} else if fdflags.is_empty() { | ||
self.0.set_nonblocking(false)?; | ||
} else { | ||
return Err(Error::invalid_argument().context("cannot set anything else than NONBLOCK")); | ||
} | ||
Ok(()) | ||
} | ||
async fn get_filestat(&self) -> Result<Filestat, Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn set_filestat_size(&self, _size: u64) -> Result<(), Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn advise(&self, _offset: u64, _len: u64, _advice: Advice) -> Result<(), Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn allocate(&self, _offset: u64, _len: u64) -> Result<(), Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn set_times( | ||
&self, | ||
_atime: Option<wasi_common::SystemTimeSpec>, | ||
_mtime: Option<wasi_common::SystemTimeSpec>, | ||
) -> Result<(), Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn read_vectored<'a>(&self, _bufs: &mut [io::IoSliceMut<'a>]) -> Result<u64, Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn read_vectored_at<'a>( | ||
&self, | ||
_bufs: &mut [io::IoSliceMut<'a>], | ||
_offset: u64, | ||
) -> Result<u64, Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn write_vectored<'a>(&self, _bufs: &[io::IoSlice<'a>]) -> Result<u64, Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn write_vectored_at<'a>( | ||
&self, | ||
_bufs: &[io::IoSlice<'a>], | ||
_offset: u64, | ||
) -> Result<u64, Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn seek(&self, _pos: std::io::SeekFrom) -> Result<u64, Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn peek(&self, _buf: &mut [u8]) -> Result<u64, Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn num_ready_bytes(&self) -> Result<u64, Error> { | ||
Ok(1) | ||
} | ||
fn isatty(&self) -> bool { | ||
false | ||
} | ||
async fn readable(&self) -> Result<(), Error> { | ||
Err(Error::badf()) | ||
} | ||
async fn writable(&self) -> Result<(), Error> { | ||
Err(Error::badf()) | ||
} | ||
} | ||
|
||
pub fn filetype_from(ft: &cap_std::fs::FileType) -> FileType { | ||
use cap_fs_ext::FileTypeExt; | ||
if ft.is_block_device() { | ||
FileType::SocketDgram | ||
} else { | ||
FileType::SocketStream | ||
} | ||
} | ||
|
||
#[cfg(windows)] | ||
use io_lifetimes::{AsSocket, BorrowedSocket}; | ||
|
||
#[cfg(windows)] | ||
impl AsSocket for TcpListener { | ||
#[inline] | ||
fn as_socket(&self) -> BorrowedSocket<'_> { | ||
self.0.as_socket() | ||
} | ||
} | ||
|
||
#[cfg(windows)] | ||
use io_extras::os::windows::{AsRawHandleOrSocket, RawHandleOrSocket}; | ||
|
||
#[cfg(windows)] | ||
impl AsRawHandleOrSocket for TcpListener { | ||
#[inline] | ||
fn as_raw_handle_or_socket(&self) -> RawHandleOrSocket { | ||
self.0.as_raw_handle_or_socket() | ||
} | ||
} | ||
|
||
#[cfg(unix)] | ||
use io_lifetimes::{AsFd, BorrowedFd}; | ||
|
||
#[cfg(unix)] | ||
impl AsFd for TcpListener { | ||
fn as_fd(&self) -> BorrowedFd<'_> { | ||
self.0.as_fd() | ||
} | ||
} | ||
|
||
pub fn from_sysif_fdflags(f: system_interface::fs::FdFlags) -> wasi_common::file::FdFlags { | ||
let mut out = wasi_common::file::FdFlags::empty(); | ||
if f.contains(system_interface::fs::FdFlags::NONBLOCK) { | ||
out |= wasi_common::file::FdFlags::NONBLOCK; | ||
} | ||
out | ||
} |
Oops, something went wrong.