add readable and writable futures to WasiFile trait
This commit is contained in:
@@ -119,6 +119,12 @@ impl WasiFile for File {
|
||||
async fn num_ready_bytes(&self) -> Result<u64, Error> {
|
||||
Ok(self.0.num_ready_bytes()?)
|
||||
}
|
||||
async fn readable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
async fn writable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filetype_from(ft: &cap_std::fs::FileType) -> FileType {
|
||||
|
||||
@@ -103,6 +103,12 @@ impl WasiFile for Stdin {
|
||||
async fn num_ready_bytes(&self) -> Result<u64, Error> {
|
||||
Ok(self.0.num_ready_bytes()?)
|
||||
}
|
||||
async fn readable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
async fn writable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
impl AsRawHandle for Stdin {
|
||||
@@ -203,6 +209,12 @@ macro_rules! wasi_file_write_impl {
|
||||
async fn num_ready_bytes(&self) -> Result<u64, Error> {
|
||||
Ok(0)
|
||||
}
|
||||
async fn readable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
async fn writable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
impl AsRawHandle for $ty {
|
||||
|
||||
@@ -36,6 +36,9 @@ pub trait WasiFile {
|
||||
async fn seek(&self, pos: std::io::SeekFrom) -> Result<u64, Error>; // file op that generates a new stream from a file will supercede this
|
||||
async fn peek(&self, buf: &mut [u8]) -> Result<u64, Error>; // read op
|
||||
async fn num_ready_bytes(&self) -> Result<u64, Error>; // read op
|
||||
|
||||
async fn readable(&mut self) -> Result<(), Error>;
|
||||
async fn writable(&mut self) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
|
||||
@@ -183,6 +183,12 @@ impl<R: Read + Any> WasiFile for ReadPipe<R> {
|
||||
async fn num_ready_bytes(&self) -> Result<u64, Error> {
|
||||
Ok(0)
|
||||
}
|
||||
async fn readable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
async fn writable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
}
|
||||
|
||||
/// A virtual pipe write end.
|
||||
@@ -336,4 +342,10 @@ impl<W: Write + Any> WasiFile for WritePipe<W> {
|
||||
async fn num_ready_bytes(&self) -> Result<u64, Error> {
|
||||
Ok(0)
|
||||
}
|
||||
async fn readable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
async fn writable(&mut self) -> Result<(), Error> {
|
||||
Err(Error::badf())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +184,12 @@ impl WasiFile for File {
|
||||
use unsafe_io::AsUnsafeFile;
|
||||
asyncify(|| self.0.as_file_view().num_ready_bytes()).await
|
||||
}
|
||||
async fn readable(&mut self) -> Result<(), Error> {
|
||||
todo!("implement this in terms of tokio::io::AsyncFd")
|
||||
}
|
||||
async fn writable(&mut self) -> Result<(), Error> {
|
||||
todo!("implement this in terms of tokio::io::AsyncFd")
|
||||
}
|
||||
}
|
||||
pub fn filetype_from(ft: &cap_std::fs::FileType) -> FileType {
|
||||
use cap_fs_ext::FileTypeExt;
|
||||
|
||||
Reference in New Issue
Block a user