feat(wasi): provide default implementations for WasiFile (#3904)

Additionally, as cleanup, remove duplicate implementations.
This commit is contained in:
Nathaniel McCallum
2022-03-09 17:38:10 -05:00
committed by GitHub
parent ae4d86804d
commit 44a435a43a
6 changed files with 99 additions and 435 deletions

View File

@@ -26,9 +26,6 @@ impl WasiFile for File {
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }
async fn sock_accept(&mut self, _fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> {
Err(Error::badf())
}
async fn datasync(&self) -> Result<(), Error> { async fn datasync(&self) -> Result<(), Error> {
self.0.sync_data()?; self.0.sync_data()?;
Ok(()) Ok(())
@@ -128,12 +125,6 @@ impl WasiFile for File {
fn isatty(&self) -> bool { fn isatty(&self) -> bool {
self.0.is_terminal() self.0.is_terminal()
} }
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 { pub fn filetype_from(ft: &cap_std::fs::FileType) -> FileType {

View File

@@ -17,7 +17,7 @@ use system_interface::fs::GetSetFdFlags;
use system_interface::io::IsReadWrite; use system_interface::io::IsReadWrite;
use system_interface::io::ReadReady; use system_interface::io::ReadReady;
use wasi_common::{ use wasi_common::{
file::{Advice, FdFlags, FileType, Filestat, WasiFile}, file::{FdFlags, FileType, WasiFile},
Error, ErrorExt, Error, ErrorExt,
}; };
@@ -91,12 +91,6 @@ macro_rules! wasi_listen_write_impl {
stream.set_fdflags(fdflags).await?; stream.set_fdflags(fdflags).await?;
Ok(Box::new(stream)) 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> { async fn get_filetype(&self) -> Result<FileType, Error> {
Ok(FileType::SocketStream) Ok(FileType::SocketStream)
} }
@@ -105,13 +99,6 @@ macro_rules! wasi_listen_write_impl {
let fdflags = self.0.as_filelike().get_fd_flags()?; let fdflags = self.0.as_filelike().get_fd_flags()?;
Ok(from_sysif_fdflags(fdflags)) Ok(from_sysif_fdflags(fdflags))
} }
#[cfg(windows)]
async fn get_fdflags(&self) -> Result<FdFlags, Error> {
// There does not seem to be a way for windows to call s.th. like `fcntl()`
// `rustix::fs::fcntl` is only available for Unix
// `rustix::io::ioctl_fionbio` only sets the flags, but does not read
Ok(FdFlags::empty())
}
async fn set_fdflags(&mut self, fdflags: FdFlags) -> Result<(), Error> { async fn set_fdflags(&mut self, fdflags: FdFlags) -> Result<(), Error> {
if fdflags == wasi_common::file::FdFlags::NONBLOCK { if fdflags == wasi_common::file::FdFlags::NONBLOCK {
self.0.set_nonblocking(true)?; self.0.set_nonblocking(true)?;
@@ -124,66 +111,9 @@ macro_rules! wasi_listen_write_impl {
} }
Ok(()) 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> { async fn num_ready_bytes(&self) -> Result<u64, Error> {
Ok(1) 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())
}
} }
#[cfg(windows)] #[cfg(windows)]
@@ -240,15 +170,6 @@ macro_rules! wasi_stream_write_impl {
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }
async fn sock_accept(&mut self, _fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> {
Err(Error::badf())
}
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> { async fn get_filetype(&self) -> Result<FileType, Error> {
Ok(FileType::SocketStream) Ok(FileType::SocketStream)
} }
@@ -257,14 +178,6 @@ macro_rules! wasi_stream_write_impl {
let fdflags = self.0.as_filelike().get_fd_flags()?; let fdflags = self.0.as_filelike().get_fd_flags()?;
Ok(from_sysif_fdflags(fdflags)) Ok(from_sysif_fdflags(fdflags))
} }
#[cfg(windows)]
async fn get_fdflags(&self) -> Result<FdFlags, Error> {
// There does not seem to be a way for windows to call s.th. like `fcntl(fd, F_GETFL, 0)`
// on a socket.
// `rustix::fs::fcntl` is only available for Unix.
// `rustix::io::ioctl_fionbio` only sets the flags, but does not read.
Ok(FdFlags::empty())
}
async fn set_fdflags(&mut self, fdflags: FdFlags) -> Result<(), Error> { async fn set_fdflags(&mut self, fdflags: FdFlags) -> Result<(), Error> {
if fdflags == wasi_common::file::FdFlags::NONBLOCK { if fdflags == wasi_common::file::FdFlags::NONBLOCK {
self.0.set_nonblocking(true)?; self.0.set_nonblocking(true)?;
@@ -277,25 +190,6 @@ macro_rules! wasi_stream_write_impl {
} }
Ok(()) 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>( async fn read_vectored<'a>(
&self, &self,
bufs: &mut [io::IoSliceMut<'a>], bufs: &mut [io::IoSliceMut<'a>],
@@ -304,28 +198,11 @@ macro_rules! wasi_stream_write_impl {
let n = Read::read_vectored(&mut *self.as_socketlike_view::<$std_ty>(), bufs)?; let n = Read::read_vectored(&mut *self.as_socketlike_view::<$std_ty>(), bufs)?;
Ok(n.try_into()?) Ok(n.try_into()?)
} }
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> { async fn write_vectored<'a>(&self, bufs: &[io::IoSlice<'a>]) -> Result<u64, Error> {
use std::io::Write; use std::io::Write;
let n = Write::write_vectored(&mut *self.as_socketlike_view::<$std_ty>(), bufs)?; let n = Write::write_vectored(&mut *self.as_socketlike_view::<$std_ty>(), bufs)?;
Ok(n.try_into()?) Ok(n.try_into()?)
} }
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> { async fn peek(&self, buf: &mut [u8]) -> Result<u64, Error> {
let n = self.0.peek(buf)?; let n = self.0.peek(buf)?;
Ok(n.try_into()?) Ok(n.try_into()?)
@@ -334,9 +211,6 @@ macro_rules! wasi_stream_write_impl {
let val = self.as_socketlike_view::<$std_ty>().num_ready_bytes()?; let val = self.as_socketlike_view::<$std_ty>().num_ready_bytes()?;
Ok(val) Ok(val)
} }
fn isatty(&self) -> bool {
false
}
async fn readable(&self) -> Result<(), Error> { async fn readable(&self) -> Result<(), Error> {
let (readable, _writeable) = self.0.is_read_write()?; let (readable, _writeable) = self.0.is_read_write()?;
if readable { if readable {

View File

@@ -16,7 +16,7 @@ use io_lifetimes::{AsFd, BorrowedFd};
#[cfg(windows)] #[cfg(windows)]
use io_lifetimes::{AsHandle, BorrowedHandle}; use io_lifetimes::{AsHandle, BorrowedHandle};
use wasi_common::{ use wasi_common::{
file::{Advice, FdFlags, FileType, Filestat, WasiFile}, file::{FdFlags, FileType, Filestat, WasiFile},
Error, ErrorExt, Error, ErrorExt,
}; };
@@ -31,12 +31,6 @@ impl WasiFile for Stdin {
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }
async fn datasync(&self) -> Result<(), Error> {
Ok(())
}
async fn sync(&self) -> Result<(), Error> {
Ok(())
}
async fn get_filetype(&self) -> Result<FileType, Error> { async fn get_filetype(&self) -> Result<FileType, Error> {
if self.isatty() { if self.isatty() {
Ok(FileType::CharacterDevice) Ok(FileType::CharacterDevice)
@@ -44,34 +38,6 @@ impl WasiFile for Stdin {
Ok(FileType::Unknown) Ok(FileType::Unknown)
} }
} }
async fn get_fdflags(&self) -> Result<FdFlags, Error> {
Ok(FdFlags::empty())
}
async fn set_fdflags(&mut self, _fdflags: FdFlags) -> Result<(), Error> {
Err(Error::badf())
}
async fn get_filestat(&self) -> Result<Filestat, Error> {
let meta = self.0.as_filelike_view::<File>().metadata()?;
Ok(Filestat {
device_id: 0,
inode: 0,
filetype: self.get_filetype().await?,
nlink: 0,
size: meta.len(),
atim: meta.accessed().ok(),
mtim: meta.modified().ok(),
ctim: meta.created().ok(),
})
}
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 read_vectored<'a>(&self, bufs: &mut [io::IoSliceMut<'a>]) -> Result<u64, Error> { async fn read_vectored<'a>(&self, bufs: &mut [io::IoSliceMut<'a>]) -> Result<u64, Error> {
let n = self.0.as_filelike_view::<File>().read_vectored(bufs)?; let n = self.0.as_filelike_view::<File>().read_vectored(bufs)?;
Ok(n.try_into().map_err(|_| Error::range())?) Ok(n.try_into().map_err(|_| Error::range())?)
@@ -83,16 +49,6 @@ impl WasiFile for Stdin {
) -> Result<u64, Error> { ) -> Result<u64, Error> {
Err(Error::seek_pipe()) Err(Error::seek_pipe())
} }
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> { async fn seek(&self, _pos: std::io::SeekFrom) -> Result<u64, Error> {
Err(Error::seek_pipe()) Err(Error::seek_pipe())
} }
@@ -114,16 +70,6 @@ impl WasiFile for Stdin {
fn isatty(&self) -> bool { fn isatty(&self) -> bool {
self.0.is_terminal() self.0.is_terminal()
} }
async fn readable(&self) -> Result<(), Error> {
Err(Error::badf())
}
async fn writable(&self) -> Result<(), Error> {
Err(Error::badf())
}
async fn sock_accept(&mut self, _fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> {
Err(Error::badf())
}
} }
#[cfg(windows)] #[cfg(windows)]
impl AsHandle for Stdin { impl AsHandle for Stdin {
@@ -152,12 +98,6 @@ macro_rules! wasi_file_write_impl {
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }
async fn datasync(&self) -> Result<(), Error> {
Ok(())
}
async fn sync(&self) -> Result<(), Error> {
Ok(())
}
async fn get_filetype(&self) -> Result<FileType, Error> { async fn get_filetype(&self) -> Result<FileType, Error> {
if self.isatty() { if self.isatty() {
Ok(FileType::CharacterDevice) Ok(FileType::CharacterDevice)
@@ -168,9 +108,6 @@ macro_rules! wasi_file_write_impl {
async fn get_fdflags(&self) -> Result<FdFlags, Error> { async fn get_fdflags(&self) -> Result<FdFlags, Error> {
Ok(FdFlags::APPEND) Ok(FdFlags::APPEND)
} }
async fn set_fdflags(&mut self, _fdflags: FdFlags) -> Result<(), Error> {
Err(Error::badf())
}
async fn get_filestat(&self) -> Result<Filestat, Error> { async fn get_filestat(&self) -> Result<Filestat, Error> {
let meta = self.0.as_filelike_view::<File>().metadata()?; let meta = self.0.as_filelike_view::<File>().metadata()?;
Ok(Filestat { Ok(Filestat {
@@ -184,28 +121,6 @@ macro_rules! wasi_file_write_impl {
ctim: meta.created().ok(), ctim: meta.created().ok(),
}) })
} }
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 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> { async fn write_vectored<'a>(&self, bufs: &[io::IoSlice<'a>]) -> Result<u64, Error> {
let n = self.0.as_filelike_view::<File>().write_vectored(bufs)?; let n = self.0.as_filelike_view::<File>().write_vectored(bufs)?;
Ok(n.try_into().map_err(|c| Error::range().context(c))?) Ok(n.try_into().map_err(|c| Error::range().context(c))?)
@@ -220,9 +135,6 @@ macro_rules! wasi_file_write_impl {
async fn seek(&self, _pos: std::io::SeekFrom) -> Result<u64, Error> { async fn seek(&self, _pos: std::io::SeekFrom) -> Result<u64, Error> {
Err(Error::seek_pipe()) Err(Error::seek_pipe())
} }
async fn peek(&self, _buf: &mut [u8]) -> Result<u64, Error> {
Err(Error::badf())
}
async fn set_times( async fn set_times(
&self, &self,
atime: Option<wasi_common::SystemTimeSpec>, atime: Option<wasi_common::SystemTimeSpec>,
@@ -232,21 +144,9 @@ macro_rules! wasi_file_write_impl {
.set_times(convert_systimespec(atime), convert_systimespec(mtime))?; .set_times(convert_systimespec(atime), convert_systimespec(mtime))?;
Ok(()) Ok(())
} }
async fn num_ready_bytes(&self) -> Result<u64, Error> {
Ok(0)
}
fn isatty(&self) -> bool { fn isatty(&self) -> bool {
self.0.is_terminal() self.0.is_terminal()
} }
async fn readable(&self) -> Result<(), Error> {
Err(Error::badf())
}
async fn writable(&self) -> Result<(), Error> {
Err(Error::badf())
}
async fn sock_accept(&mut self, _fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> {
Err(Error::badf())
}
} }
#[cfg(windows)] #[cfg(windows)]
impl AsHandle for $ty { impl AsHandle for $ty {

View File

@@ -5,40 +5,108 @@ use std::any::Any;
#[wiggle::async_trait] #[wiggle::async_trait]
pub trait WasiFile: Send + Sync { pub trait WasiFile: Send + Sync {
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;
async fn sock_accept(&mut self, fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error>; async fn get_filetype(&self) -> Result<FileType, Error>;
async fn datasync(&self) -> Result<(), Error>; // write op
async fn sync(&self) -> Result<(), Error>; // file op fn isatty(&self) -> bool {
async fn get_filetype(&self) -> Result<FileType, Error>; // file op false
async fn get_fdflags(&self) -> Result<FdFlags, Error>; // file op }
async fn set_fdflags(&mut self, flags: FdFlags) -> Result<(), Error>; // file op
async fn get_filestat(&self) -> Result<Filestat, Error>; // split out get_length as a read & write op, rest is a file op async fn sock_accept(&mut self, _fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> {
async fn set_filestat_size(&self, _size: u64) -> Result<(), Error>; // write op Err(Error::badf())
async fn advise(&self, offset: u64, len: u64, advice: Advice) -> Result<(), Error>; // file op }
async fn allocate(&self, offset: u64, len: u64) -> Result<(), Error>; // write op
async fn datasync(&self) -> Result<(), Error> {
Ok(())
}
async fn sync(&self) -> Result<(), Error> {
Ok(())
}
async fn get_fdflags(&self) -> Result<FdFlags, Error> {
Ok(FdFlags::empty())
}
async fn set_fdflags(&mut self, _flags: FdFlags) -> Result<(), Error> {
Err(Error::badf())
}
async fn get_filestat(&self) -> Result<Filestat, Error> {
Ok(Filestat {
device_id: 0,
inode: 0,
filetype: self.get_filetype().await?,
nlink: 0,
size: 0, // XXX no way to get a size out of a Read :(
atim: None,
mtim: None,
ctim: None,
})
}
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( async fn set_times(
&self, &self,
atime: Option<SystemTimeSpec>, _atime: Option<SystemTimeSpec>,
mtime: Option<SystemTimeSpec>, _mtime: Option<SystemTimeSpec>,
) -> Result<(), Error>; ) -> Result<(), Error> {
async fn read_vectored<'a>(&self, bufs: &mut [std::io::IoSliceMut<'a>]) -> Result<u64, Error>; // read op Err(Error::badf())
}
async fn read_vectored<'a>(&self, _bufs: &mut [std::io::IoSliceMut<'a>]) -> Result<u64, Error> {
Err(Error::badf())
}
async fn read_vectored_at<'a>( async fn read_vectored_at<'a>(
&self, &self,
bufs: &mut [std::io::IoSliceMut<'a>], _bufs: &mut [std::io::IoSliceMut<'a>],
offset: u64, _offset: u64,
) -> Result<u64, Error>; // file op ) -> Result<u64, Error> {
async fn write_vectored<'a>(&self, bufs: &[std::io::IoSlice<'a>]) -> Result<u64, Error>; // write op Err(Error::badf())
}
async fn write_vectored<'a>(&self, _bufs: &[std::io::IoSlice<'a>]) -> Result<u64, Error> {
Err(Error::badf())
}
async fn write_vectored_at<'a>( async fn write_vectored_at<'a>(
&self, &self,
bufs: &[std::io::IoSlice<'a>], _bufs: &[std::io::IoSlice<'a>],
offset: u64, _offset: u64,
) -> Result<u64, Error>; // file op ) -> Result<u64, Error> {
async fn seek(&self, pos: std::io::SeekFrom) -> Result<u64, Error>; // file op that generates a new stream from a file will supercede this Err(Error::badf())
async fn peek(&self, buf: &mut [u8]) -> Result<u64, Error>; // read op }
async fn num_ready_bytes(&self) -> Result<u64, Error>; // read op
fn isatty(&self) -> bool;
async fn readable(&self) -> Result<(), Error>; async fn seek(&self, _pos: std::io::SeekFrom) -> Result<u64, Error> {
async fn writable(&self) -> Result<(), 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(0)
}
async fn readable(&self) -> Result<(), Error> {
Err(Error::badf())
}
async fn writable(&self) -> Result<(), Error> {
Err(Error::badf())
}
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]

View File

@@ -9,10 +9,8 @@
//! Some convenience constructors are included for common backing types like `Vec<u8>` and `String`, //! Some convenience constructors are included for common backing types like `Vec<u8>` and `String`,
//! but the virtual pipes can be instantiated with any `Read` or `Write` type. //! but the virtual pipes can be instantiated with any `Read` or `Write` type.
//! //!
use crate::{ use crate::file::{FdFlags, FileType, WasiFile};
file::{Advice, FdFlags, FileType, Filestat, WasiFile}, use crate::Error;
Error, ErrorExt, SystemTimeSpec,
};
use std::any::Any; use std::any::Any;
use std::convert::TryInto; use std::convert::TryInto;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
@@ -107,92 +105,13 @@ impl<R: Read + Any + Send + Sync> WasiFile for ReadPipe<R> {
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }
async fn datasync(&self) -> Result<(), Error> {
Ok(()) // trivial: no implementation needed
}
async fn sync(&self) -> Result<(), Error> {
Ok(()) // trivial
}
async fn get_filetype(&self) -> Result<FileType, Error> { async fn get_filetype(&self) -> Result<FileType, Error> {
Ok(FileType::Pipe) Ok(FileType::Pipe)
} }
async fn get_fdflags(&self) -> Result<FdFlags, Error> {
Ok(FdFlags::empty())
}
async fn set_fdflags(&mut self, _fdflags: FdFlags) -> Result<(), Error> {
Err(Error::badf())
}
async fn get_filestat(&self) -> Result<Filestat, Error> {
Ok(Filestat {
device_id: 0,
inode: 0,
filetype: self.get_filetype().await?,
nlink: 0,
size: 0, // XXX no way to get a size out of a Read :(
atim: None,
mtim: None,
ctim: None,
})
}
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 read_vectored<'a>(&self, bufs: &mut [io::IoSliceMut<'a>]) -> Result<u64, Error> { async fn read_vectored<'a>(&self, bufs: &mut [io::IoSliceMut<'a>]) -> Result<u64, Error> {
let n = self.borrow().read_vectored(bufs)?; let n = self.borrow().read_vectored(bufs)?;
Ok(n.try_into()?) Ok(n.try_into()?)
} }
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 set_times(
&self,
atime: Option<SystemTimeSpec>,
mtime: Option<SystemTimeSpec>,
) -> Result<(), Error> {
Err(Error::badf())
}
async fn num_ready_bytes(&self) -> Result<u64, Error> {
Ok(0)
}
fn isatty(&self) -> bool {
false
}
async fn readable(&self) -> Result<(), Error> {
Err(Error::badf())
}
async fn writable(&self) -> Result<(), Error> {
Err(Error::badf())
}
async fn sock_accept(&mut self, fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> {
Err(Error::badf())
}
} }
/// A virtual pipe write end. /// A virtual pipe write end.
@@ -270,90 +189,14 @@ impl<W: Write + Any + Send + Sync> WasiFile for WritePipe<W> {
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }
async fn datasync(&self) -> Result<(), Error> {
Ok(())
}
async fn sync(&self) -> Result<(), Error> {
Ok(())
}
async fn get_filetype(&self) -> Result<FileType, Error> { async fn get_filetype(&self) -> Result<FileType, Error> {
Ok(FileType::Pipe) Ok(FileType::Pipe)
} }
async fn get_fdflags(&self) -> Result<FdFlags, Error> { async fn get_fdflags(&self) -> Result<FdFlags, Error> {
Ok(FdFlags::APPEND) Ok(FdFlags::APPEND)
} }
async fn set_fdflags(&mut self, _fdflags: FdFlags) -> Result<(), Error> {
Err(Error::badf())
}
async fn get_filestat(&self) -> Result<Filestat, Error> {
Ok(Filestat {
device_id: 0,
inode: 0,
filetype: self.get_filetype().await?,
nlink: 0,
size: 0, // XXX no way to get a size out of a Write :(
atim: None,
mtim: None,
ctim: None,
})
}
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 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> { async fn write_vectored<'a>(&self, bufs: &[io::IoSlice<'a>]) -> Result<u64, Error> {
let n = self.borrow().write_vectored(bufs)?; let n = self.borrow().write_vectored(bufs)?;
Ok(n.try_into()?) Ok(n.try_into()?)
} }
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 set_times(
&self,
atime: Option<SystemTimeSpec>,
mtime: Option<SystemTimeSpec>,
) -> Result<(), Error> {
Err(Error::badf())
}
async fn num_ready_bytes(&self) -> Result<u64, Error> {
Ok(0)
}
fn isatty(&self) -> bool {
false
}
async fn readable(&self) -> Result<(), Error> {
Err(Error::badf())
}
async fn writable(&self) -> Result<(), Error> {
Err(Error::badf())
}
async fn sock_accept(&mut self, fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> {
Err(Error::badf())
}
} }

View File

@@ -187,12 +187,6 @@ macro_rules! wasi_file_impl {
Err(e) => Err(e.into()), Err(e) => Err(e.into()),
} }
} }
#[cfg(windows)]
async fn readable(&self) -> Result<(), Error> {
// Windows uses a rawfd based scheduler :(
use wasi_common::ErrorExt;
Err(Error::badf())
}
#[cfg(not(windows))] #[cfg(not(windows))]
async fn writable(&self) -> Result<(), Error> { async fn writable(&self) -> Result<(), Error> {
@@ -217,12 +211,6 @@ macro_rules! wasi_file_impl {
Err(e) => Err(e.into()), Err(e) => Err(e.into()),
} }
} }
#[cfg(windows)]
async fn writable(&self) -> Result<(), Error> {
// Windows uses a rawfd based scheduler :(
use wasi_common::ErrorExt;
Err(Error::badf())
}
async fn sock_accept(&mut self, fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> { async fn sock_accept(&mut self, fdflags: FdFlags) -> Result<Box<dyn WasiFile>, Error> {
block_on_dummy_executor(|| self.0.sock_accept(fdflags)) block_on_dummy_executor(|| self.0.sock_accept(fdflags))