Fix a bug in poll's handling of input pollfds

This commit is contained in:
Tate, Hongliang Tian 2020-11-17 15:48:18 +00:00 committed by Zongmin.Gu
parent 554f7dd2c5
commit 5b6d06b808
2 changed files with 10 additions and 9 deletions

@ -200,17 +200,12 @@ impl EventMonitorBuilder {
} }
pub fn add_file(&mut self, file: FileRef, events: IoEvents) { pub fn add_file(&mut self, file: FileRef, events: IoEvents) {
let host_file_idx = if file.host_fd().is_some() { if file.host_fd().is_some() {
Some(self.files_and_events.len()) let host_file_idx = self.files_and_events.len();
} else {
None
};
self.files_and_events.push((file, events));
if let Some(host_file_idx) = host_file_idx {
self.host_file_idxes.push(host_file_idx); self.host_file_idxes.push(host_file_idx);
} }
self.files_and_events.push((file, events));
} }
fn init_ocall_pollfds(&mut self) { fn init_ocall_pollfds(&mut self) {

@ -13,6 +13,12 @@ mod event_monitor;
pub fn do_poll_new(poll_fds: &[PollFd], mut timeout: Option<&mut Duration>) -> Result<usize> { pub fn do_poll_new(poll_fds: &[PollFd], mut timeout: Option<&mut Duration>) -> Result<usize> {
debug!("poll: poll_fds: {:?}, timeout: {:?}", poll_fds, timeout); debug!("poll: poll_fds: {:?}, timeout: {:?}", poll_fds, timeout);
// Always clear the revents fields first
for poll_fd in poll_fds {
poll_fd.revents.set(IoEvents::empty());
}
// Map poll_fds to FileRef's
let thread = current!(); let thread = current!();
let files: Vec<FileRef> = poll_fds let files: Vec<FileRef> = poll_fds
.iter() .iter()