From b307dce2abcf24f141d3a63cc48a65dc4b655224 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 26 Apr 2021 14:43:16 -0700 Subject: [PATCH] add readable and writable futures to WasiFile trait --- crates/wasi-common/cap-std-sync/src/file.rs | 6 ++++++ crates/wasi-common/cap-std-sync/src/stdio.rs | 12 ++++++++++++ crates/wasi-common/src/file.rs | 3 +++ crates/wasi-common/src/pipe.rs | 12 ++++++++++++ crates/wasi-common/tokio/src/file.rs | 6 ++++++ 5 files changed, 39 insertions(+) diff --git a/crates/wasi-common/cap-std-sync/src/file.rs b/crates/wasi-common/cap-std-sync/src/file.rs index ba9ff2743a..751c5f21b1 100644 --- a/crates/wasi-common/cap-std-sync/src/file.rs +++ b/crates/wasi-common/cap-std-sync/src/file.rs @@ -119,6 +119,12 @@ impl WasiFile for File { async fn num_ready_bytes(&self) -> Result { 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 { diff --git a/crates/wasi-common/cap-std-sync/src/stdio.rs b/crates/wasi-common/cap-std-sync/src/stdio.rs index d4d515cfeb..d86d181399 100644 --- a/crates/wasi-common/cap-std-sync/src/stdio.rs +++ b/crates/wasi-common/cap-std-sync/src/stdio.rs @@ -103,6 +103,12 @@ impl WasiFile for Stdin { async fn num_ready_bytes(&self) -> Result { 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 { 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 { diff --git a/crates/wasi-common/src/file.rs b/crates/wasi-common/src/file.rs index b8eadb3673..dede0c0dc3 100644 --- a/crates/wasi-common/src/file.rs +++ b/crates/wasi-common/src/file.rs @@ -36,6 +36,9 @@ pub trait WasiFile { async fn seek(&self, pos: std::io::SeekFrom) -> Result; // file op that generates a new stream from a file will supercede this async fn peek(&self, buf: &mut [u8]) -> Result; // read op async fn num_ready_bytes(&self) -> Result; // read op + + async fn readable(&mut self) -> Result<(), Error>; + async fn writable(&mut self) -> Result<(), Error>; } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/wasi-common/src/pipe.rs b/crates/wasi-common/src/pipe.rs index 5e5d418767..192fe5d10a 100644 --- a/crates/wasi-common/src/pipe.rs +++ b/crates/wasi-common/src/pipe.rs @@ -183,6 +183,12 @@ impl WasiFile for ReadPipe { async fn num_ready_bytes(&self) -> Result { 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 WasiFile for WritePipe { async fn num_ready_bytes(&self) -> Result { Ok(0) } + async fn readable(&mut self) -> Result<(), Error> { + Err(Error::badf()) + } + async fn writable(&mut self) -> Result<(), Error> { + Err(Error::badf()) + } } diff --git a/crates/wasi-common/tokio/src/file.rs b/crates/wasi-common/tokio/src/file.rs index 503e2168c4..a47e6b4ccf 100644 --- a/crates/wasi-common/tokio/src/file.rs +++ b/crates/wasi-common/tokio/src/file.rs @@ -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;