Skip to content

Commit

Permalink
feat(core): add timeout and interrupt handling to VmiHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenny committed Nov 24, 2024
1 parent bf685e4 commit 05d00a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion crates/vmi-core/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{VmiContext, VmiDriver, VmiEventResponse, VmiOs};
use crate::{VmiContext, VmiDriver, VmiEventResponse, VmiOs, VmiSession};

/// A trait for handling VMI events.
///
Expand All @@ -17,6 +17,12 @@ where
event: VmiContext<Driver, Os>,
) -> VmiEventResponse<Driver::Architecture>;

/// Handles a timeout event.
fn handle_timeout(&mut self, _session: &VmiSession<Driver, Os>) {}

/// Handles an interrupted event.
fn handle_interrupted(&mut self, _session: &VmiSession<Driver, Os>) {}

/// Returns whether the handler has finished processing events.
fn finished(&self) -> bool {
false
Expand Down
4 changes: 3 additions & 1 deletion crates/vmi-core/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ where
match self.wait_for_event(timeout, &mut handler) {
Err(VmiError::Timeout) => {
tracing::trace!("timeout");
handler.handle_timeout(self);
}
Err(VmiError::Io(err)) if err.kind() == ErrorKind::Interrupted => {
tracing::info!("interrupted");
tracing::trace!("interrupted");
handler.handle_interrupted(self);
break;
}
Err(err) => return Err(err),
Expand Down

0 comments on commit 05d00a3

Please sign in to comment.