restructure Poll to hold a Table and fd instead of a RefMut<dyn WasiFile>

unfortunately, the borrow checker defeated me: changing the
RwSubscription file form a Ref to a RefMut turned into borrow checker
errors in the impl of the poll_oneoff trait method.

This implementation makes an end run by having Poll hold onto the table
and fd, and borrow the file at the site of use, rather than try to own
the RefMut. I have no idea why this convinces the borrow checker that
anything is different, but it does and I need to get this PR done and
I don't think comprimising on this internal abstraction is worth
fighting against
This commit is contained in:
Pat Hickey
2021-04-28 11:56:48 -07:00
parent 02581ddda0
commit b3e1ab4553
6 changed files with 72 additions and 70 deletions

View File

@@ -32,14 +32,14 @@ impl WasiSched for SyncSched {
for s in poll.rw_subscriptions() {
match s {
Subscription::Read(f) => {
let raw_fd = wasi_file_raw_fd(f.file.deref()).ok_or(
let raw_fd = wasi_file_raw_fd(f.file()?.deref()).ok_or(
Error::invalid_argument().context("read subscription fd downcast failed"),
)?;
pollfds.push(unsafe { PollFd::new(raw_fd, PollFlags::POLLIN) });
}
Subscription::Write(f) => {
let raw_fd = wasi_file_raw_fd(f.file.deref()).ok_or(
let raw_fd = wasi_file_raw_fd(f.file()?.deref()).ok_or(
Error::invalid_argument().context("write subscription fd downcast failed"),
)?;
pollfds.push(unsafe { PollFd::new(raw_fd, PollFlags::POLLOUT) });
@@ -79,7 +79,11 @@ impl WasiSched for SyncSched {
if let Some(revents) = pollfd.revents() {
let (nbytes, rwsub) = match rwsub {
Subscription::Read(sub) => {
let ready = sub.file.num_ready_bytes().await?;
let ready = sub
.file()
.expect("validated file already")
.num_ready_bytes()
.await?;
(std::cmp::max(ready, 1), sub)
}
Subscription::Write(sub) => (0, sub),