Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation for poll on pipe #3873

Merged
merged 4 commits into from
May 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/wasi/src/fs/inode_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,6 +29,7 @@ pub(crate) enum InodeValFilePollGuardMode {
File(Arc<RwLock<Box<dyn VirtualFile + Send + Sync + 'static>>>),
EventNotifications(Arc<NotificationInner>),
Socket { inner: Arc<InodeSocketInner> },
Pipe { pipe: Arc<RwLock<Box<VirtualPipe>>> },
}

pub(crate) struct InodeValFilePollGuard {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(...)")
}
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down