Skip to content

Commit

Permalink
Initial implementation for poll on pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb authored and theduke committed May 24, 2023
1 parent 2daaa78 commit 8df6792
Showing 1 changed file with 23 additions and 1 deletion.
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

0 comments on commit 8df6792

Please sign in to comment.