wasi-cap-std-sync: WasiFile and WasiDir converted to async_traits
This commit is contained in:
@@ -22,31 +22,32 @@ pub fn stdin() -> Stdin {
|
||||
Stdin(std::io::stdin())
|
||||
}
|
||||
|
||||
#[wiggle::async_trait]
|
||||
impl WasiFile for Stdin {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
fn datasync(&self) -> Result<(), Error> {
|
||||
async fn datasync(&self) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn sync(&self) -> Result<(), Error> {
|
||||
async fn sync(&self) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn get_filetype(&self) -> Result<FileType, Error> {
|
||||
async fn get_filetype(&self) -> Result<FileType, Error> {
|
||||
Ok(FileType::Unknown)
|
||||
}
|
||||
fn get_fdflags(&self) -> Result<FdFlags, Error> {
|
||||
async fn get_fdflags(&self) -> Result<FdFlags, Error> {
|
||||
Ok(FdFlags::empty())
|
||||
}
|
||||
fn set_fdflags(&mut self, _fdflags: FdFlags) -> Result<(), Error> {
|
||||
async fn set_fdflags(&mut self, _fdflags: FdFlags) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn get_filestat(&self) -> Result<Filestat, Error> {
|
||||
async fn get_filestat(&self) -> Result<Filestat, Error> {
|
||||
let meta = self.0.as_file_view().metadata()?;
|
||||
Ok(Filestat {
|
||||
device_id: 0,
|
||||
inode: 0,
|
||||
filetype: self.get_filetype()?,
|
||||
filetype: self.get_filetype().await?,
|
||||
nlink: 0,
|
||||
size: meta.len(),
|
||||
atim: meta.accessed().ok(),
|
||||
@@ -54,35 +55,43 @@ impl WasiFile for Stdin {
|
||||
ctim: meta.created().ok(),
|
||||
})
|
||||
}
|
||||
fn set_filestat_size(&self, _size: u64) -> Result<(), Error> {
|
||||
async fn set_filestat_size(&self, _size: u64) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn advise(&self, _offset: u64, _len: u64, _advice: Advice) -> Result<(), Error> {
|
||||
async fn advise(&self, _offset: u64, _len: u64, _advice: Advice) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn allocate(&self, _offset: u64, _len: u64) -> Result<(), Error> {
|
||||
async fn allocate(&self, _offset: u64, _len: u64) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn read_vectored(&self, bufs: &mut [io::IoSliceMut]) -> Result<u64, Error> {
|
||||
async fn read_vectored<'a>(&self, bufs: &mut [io::IoSliceMut<'a>]) -> Result<u64, Error> {
|
||||
let n = self.0.as_file_view().read_vectored(bufs)?;
|
||||
Ok(n.try_into().map_err(|_| Error::range())?)
|
||||
}
|
||||
fn read_vectored_at(&self, _bufs: &mut [io::IoSliceMut], _offset: u64) -> Result<u64, Error> {
|
||||
async fn read_vectored_at<'a>(
|
||||
&self,
|
||||
_bufs: &mut [io::IoSliceMut<'a>],
|
||||
_offset: u64,
|
||||
) -> Result<u64, Error> {
|
||||
Err(Error::seek_pipe())
|
||||
}
|
||||
fn write_vectored(&self, _bufs: &[io::IoSlice]) -> Result<u64, Error> {
|
||||
async fn write_vectored<'a>(&self, _bufs: &[io::IoSlice<'a>]) -> Result<u64, Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn write_vectored_at(&self, _bufs: &[io::IoSlice], _offset: u64) -> Result<u64, Error> {
|
||||
async fn write_vectored_at<'a>(
|
||||
&self,
|
||||
_bufs: &[io::IoSlice<'a>],
|
||||
_offset: u64,
|
||||
) -> Result<u64, Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
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())
|
||||
}
|
||||
fn peek(&self, _buf: &mut [u8]) -> Result<u64, Error> {
|
||||
async fn peek(&self, _buf: &mut [u8]) -> Result<u64, Error> {
|
||||
Err(Error::seek_pipe())
|
||||
}
|
||||
fn set_times(
|
||||
async fn set_times(
|
||||
&self,
|
||||
atime: Option<wasi_common::SystemTimeSpec>,
|
||||
mtime: Option<wasi_common::SystemTimeSpec>,
|
||||
@@ -91,7 +100,7 @@ impl WasiFile for Stdin {
|
||||
.set_times(convert_systimespec(atime), convert_systimespec(mtime))?;
|
||||
Ok(())
|
||||
}
|
||||
fn num_ready_bytes(&self) -> Result<u64, Error> {
|
||||
async fn num_ready_bytes(&self) -> Result<u64, Error> {
|
||||
Ok(self.0.num_ready_bytes()?)
|
||||
}
|
||||
}
|
||||
@@ -110,31 +119,32 @@ impl AsRawFd for Stdin {
|
||||
|
||||
macro_rules! wasi_file_write_impl {
|
||||
($ty:ty) => {
|
||||
#[wiggle::async_trait]
|
||||
impl WasiFile for $ty {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
fn datasync(&self) -> Result<(), Error> {
|
||||
async fn datasync(&self) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn sync(&self) -> Result<(), Error> {
|
||||
async fn sync(&self) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn get_filetype(&self) -> Result<FileType, Error> {
|
||||
async fn get_filetype(&self) -> Result<FileType, Error> {
|
||||
Ok(FileType::Unknown)
|
||||
}
|
||||
fn get_fdflags(&self) -> Result<FdFlags, Error> {
|
||||
async fn get_fdflags(&self) -> Result<FdFlags, Error> {
|
||||
Ok(FdFlags::APPEND)
|
||||
}
|
||||
fn set_fdflags(&mut self, _fdflags: FdFlags) -> Result<(), Error> {
|
||||
async fn set_fdflags(&mut self, _fdflags: FdFlags) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn get_filestat(&self) -> Result<Filestat, Error> {
|
||||
async fn get_filestat(&self) -> Result<Filestat, Error> {
|
||||
let meta = self.0.as_file_view().metadata()?;
|
||||
Ok(Filestat {
|
||||
device_id: 0,
|
||||
inode: 0,
|
||||
filetype: self.get_filetype()?,
|
||||
filetype: self.get_filetype().await?,
|
||||
nlink: 0,
|
||||
size: meta.len(),
|
||||
atim: meta.accessed().ok(),
|
||||
@@ -142,39 +152,46 @@ macro_rules! wasi_file_write_impl {
|
||||
ctim: meta.created().ok(),
|
||||
})
|
||||
}
|
||||
fn set_filestat_size(&self, _size: u64) -> Result<(), Error> {
|
||||
async fn set_filestat_size(&self, _size: u64) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn advise(&self, _offset: u64, _len: u64, _advice: Advice) -> Result<(), Error> {
|
||||
async fn advise(&self, _offset: u64, _len: u64, _advice: Advice) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn allocate(&self, _offset: u64, _len: u64) -> Result<(), Error> {
|
||||
async fn allocate(&self, _offset: u64, _len: u64) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn read_vectored(&self, _bufs: &mut [io::IoSliceMut]) -> Result<u64, Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn read_vectored_at(
|
||||
async fn read_vectored<'a>(
|
||||
&self,
|
||||
_bufs: &mut [io::IoSliceMut],
|
||||
_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())
|
||||
}
|
||||
fn write_vectored(&self, bufs: &[io::IoSlice]) -> Result<u64, Error> {
|
||||
async fn write_vectored<'a>(&self, bufs: &[io::IoSlice<'a>]) -> Result<u64, Error> {
|
||||
let n = self.0.as_file_view().write_vectored(bufs)?;
|
||||
Ok(n.try_into().map_err(|c| Error::range().context(c))?)
|
||||
}
|
||||
fn write_vectored_at(&self, _bufs: &[io::IoSlice], _offset: u64) -> Result<u64, Error> {
|
||||
async fn write_vectored_at<'a>(
|
||||
&self,
|
||||
_bufs: &[io::IoSlice<'a>],
|
||||
_offset: u64,
|
||||
) -> Result<u64, Error> {
|
||||
Err(Error::seek_pipe())
|
||||
}
|
||||
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())
|
||||
}
|
||||
fn peek(&self, _buf: &mut [u8]) -> Result<u64, Error> {
|
||||
async fn peek(&self, _buf: &mut [u8]) -> Result<u64, Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
fn set_times(
|
||||
async fn set_times(
|
||||
&self,
|
||||
atime: Option<wasi_common::SystemTimeSpec>,
|
||||
mtime: Option<wasi_common::SystemTimeSpec>,
|
||||
@@ -183,7 +200,7 @@ macro_rules! wasi_file_write_impl {
|
||||
.set_times(convert_systimespec(atime), convert_systimespec(mtime))?;
|
||||
Ok(())
|
||||
}
|
||||
fn num_ready_bytes(&self) -> Result<u64, Error> {
|
||||
async fn num_ready_bytes(&self) -> Result<u64, Error> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user