Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions lib/virtual-io/src/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,42 @@ pub enum HandlerGuardState {
WakerMap(InterestGuard, InterestWakerMap),
}

/// The full set of interests we register sources with. Includes priority
/// (EPOLLPRI, e.g. TCP out-of-band data) on platforms that support it.
pub fn all_interests() -> mio::Interest {
#[cfg(any(target_os = "linux", target_os = "android"))]
{
mio::Interest::READABLE | mio::Interest::WRITABLE | mio::Interest::PRIORITY
}
#[cfg(not(any(target_os = "linux", target_os = "android")))]
{
mio::Interest::READABLE | mio::Interest::WRITABLE
}
}

pub fn state_as_waker_map<'a>(
state: &'a mut HandlerGuardState,
selector: &'_ Arc<Selector>,
source: &'_ mut dyn mio::event::Source,
) -> io::Result<&'a mut InterestWakerMap> {
state_as_waker_map_with_interests(
state,
selector,
source,
mio::Interest::READABLE | mio::Interest::WRITABLE,
)
}

pub fn state_as_waker_map_with_interests<'a>(
state: &'a mut HandlerGuardState,
selector: &'_ Arc<Selector>,
source: &'_ mut dyn mio::event::Source,
interests: mio::Interest,
) -> io::Result<&'a mut InterestWakerMap> {
if !matches!(state, HandlerGuardState::WakerMap(_, _)) {
let waker_map = InterestWakerMap::default();
*state = HandlerGuardState::WakerMap(
InterestGuard::new(
selector,
Box::new(waker_map.clone()),
source,
mio::Interest::READABLE | mio::Interest::WRITABLE,
)?,
InterestGuard::new(selector, Box::new(waker_map.clone()), source, interests)?,
waker_map,
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/virtual-io/src/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub enum InterestType {
Writable,
Closed,
Error,
// e.g. TCP out-of-band data
Priority,
}

#[derive(Debug)]
Expand Down
5 changes: 5 additions & 0 deletions lib/virtual-io/src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl SelectorModification {
InterestType::Writable,
InterestType::Closed,
InterestType::Error,
InterestType::Priority,
];
for interest in interests {
if last.has_interest(interest) && !handler.has_interest(interest) {
Expand Down Expand Up @@ -277,6 +278,10 @@ impl Selector {
tracing::trace!(token = ?token, interest = ?InterestType::Error, "host epoll");
handler.push_interest(InterestType::Error);
}
if event.is_priority() {
tracing::trace!(token = ?token, interest = ?InterestType::Priority, "host epoll");
handler.push_interest(InterestType::Priority);
}
}
}
}
Expand Down
Loading
Loading