hmm this code is challenging

This commit is contained in:
Pat Hickey
2020-08-18 16:22:15 -07:00
parent e08173da9e
commit 9286bb8f08

View File

@@ -24,7 +24,7 @@ enum PollState {
Ready, Ready,
NotReady, // it's not ready, but we didn't wait NotReady, // it's not ready, but we didn't wait
TimedOut, // it's not ready and a timeout has occurred TimedOut, // it's not ready and a timeout has occurred
Error(Error), Error(types::Errno),
} }
enum WaitMode { enum WaitMode {
@@ -80,7 +80,7 @@ impl StdinPoll {
// Linux returns `POLLIN` in both cases, and we imitate this behavior. // Linux returns `POLLIN` in both cases, and we imitate this behavior.
let resp = match std::io::stdin().lock().fill_buf() { let resp = match std::io::stdin().lock().fill_buf() {
Ok(_) => PollState::Ready, Ok(_) => PollState::Ready,
Err(e) => PollState::Error(Error::from(e)), Err(e) => PollState::Error(types::Errno::from(Error::from(e))),
}; };
// Notify the requestor about data in stdin. They may have already timed out, // Notify the requestor about data in stdin. They may have already timed out,
@@ -177,8 +177,8 @@ fn handle_rw_event(event: FdEventData, out_events: &mut Vec<types::Event>) {
out_events.push(new_event); out_events.push(new_event);
} }
fn handle_error_event(event: FdEventData, error: &Error, out_events: &mut Vec<types::Event>) { fn handle_error_event(event: FdEventData, error: types::Errno, out_events: &mut Vec<types::Event>) {
let new_event = make_rw_event(&event, Err(error.into())); let new_event = make_rw_event(&event, Err(error));
out_events.push(new_event); out_events.push(new_event);
} }
@@ -242,7 +242,7 @@ pub(crate) fn oneoff(
"poll_oneoff: unsupported file type: {}", "poll_oneoff: unsupported file type: {}",
other.get_file_type() other.get_file_type()
); );
handle_error_event(event, &Error::Notsup, events); handle_error_event(event, types::Errno::Notsup, events);
} }
} else { } else {
log::error!("can poll FdEvent for OS resources only"); log::error!("can poll FdEvent for OS resources only");
@@ -294,7 +294,7 @@ pub(crate) fn oneoff(
PollState::Ready => handle_rw_event(event, events), PollState::Ready => handle_rw_event(event, events),
PollState::NotReady => {} // not immediately available, so just ignore PollState::NotReady => {} // not immediately available, so just ignore
PollState::TimedOut => handle_timeout_event(timeout.unwrap().0, events), PollState::TimedOut => handle_timeout_event(timeout.unwrap().0, events),
PollState::Error(ref e) => handle_error_event(event, e, events), PollState::Error(e) => handle_error_event(event, e, events),
} }
} }
} }