diff --git a/lib/wasi/src/fs/inode_guard.rs b/lib/wasi/src/fs/inode_guard.rs index e357d6609c7..1df3554a36b 100644 --- a/lib/wasi/src/fs/inode_guard.rs +++ b/lib/wasi/src/fs/inode_guard.rs @@ -9,7 +9,7 @@ use std::{ }; use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite}; -use virtual_fs::{FsError, VirtualFile}; +use virtual_fs::{FsError, Pipe as VirtualPipe, VirtualFile}; use virtual_net::NetworkError; use wasmer_wasix_types::{ types::Eventtype, @@ -29,6 +29,7 @@ pub(crate) enum InodeValFilePollGuardMode { File(Arc>>), EventNotifications(Arc), Socket { inner: Arc }, + Pipe { pipe: Arc>> }, } pub(crate) struct InodeValFilePollGuard { @@ -56,6 +57,9 @@ impl InodeValFilePollGuard { handle: Some(handle), .. } => InodeValFilePollGuardMode::File(handle.clone()), + Kind::Pipe { pipe } => InodeValFilePollGuardMode::Pipe { + pipe: Arc::new(RwLock::new(Box::new(pipe.clone()))), + }, _ => { return None; } @@ -104,6 +108,9 @@ impl std::fmt::Debug for InodeValFilePollGuard { _ => write!(f, "guard-socket(fd={}), peb={})", self.fd, self.peb), } } + InodeValFilePollGuardMode::Pipe { .. } => { + write!(f, "guard-pipe(...)") + } } } } @@ -196,6 +203,11 @@ impl Future for InodeValFilePollGuardJoin { false } } + InodeValFilePollGuardMode::Pipe { pipe } => { + let mut guard = pipe.write().unwrap(); + let pipe = Pin::new(guard.as_mut()); + pipe.poll_shutdown(cx).is_ready() + } }; if is_closed { ret.push(EventResult { @@ -257,6 +269,11 @@ impl Future for InodeValFilePollGuardJoin { Poll::Pending => Poll::Pending, } } + InodeValFilePollGuardMode::Pipe { pipe } => { + let mut guard = pipe.write().unwrap(); + let pipe = Pin::new(guard.as_mut()); + pipe.poll_read_ready(cx) + } }; match poll_result { Poll::Ready(Err(err)) if has_close && is_err_closed(&err) => { @@ -350,6 +367,11 @@ impl Future for InodeValFilePollGuardJoin { Poll::Pending => Poll::Pending, } } + InodeValFilePollGuardMode::Pipe { pipe } => { + let mut guard = pipe.write().unwrap(); + let pipe = Pin::new(guard.as_mut()); + pipe.poll_write_ready(cx) + } }; match poll_result { Poll::Ready(Err(err)) if has_close && is_err_closed(&err) => {