Skip to content
Draft
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
20 changes: 13 additions & 7 deletions lading/src/neper/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//! ([`FlowMap`]), and the [`Action`] enum that event handlers return to
//! drive flow lifecycle.

use std::io;

use mio::net::TcpStream;
use mio::{Interest, Registry, Token};

Expand Down Expand Up @@ -63,27 +65,31 @@ impl<S> FlowMap<S> {
}

/// Apply an [`Action`] to a flow via the poll registry.
///
/// # Errors
///
/// Returns the underlying `io::Error` if the registry rejects the reregister
/// or deregister. A live, owned flow should always accept both, so a failure
/// here means the thread's event loop can no longer be driven correctly and
/// the caller is expected to treat it as fatal for that thread.
pub(crate) fn apply_action<S>(
action: Action,
token: Token,
flows: &mut FlowMap<S>,
registry: &Registry,
) {
) -> io::Result<()> {
match action {
Action::Continue => {}
Action::Reregister(interest) => {
if let Some(flow) = flows.get_mut(token) {
registry
.reregister(&mut flow.stream, flow.token, interest)
.expect("reregister of a live, owned flow must succeed");
registry.reregister(&mut flow.stream, flow.token, interest)?;
}
}
Action::Remove => {
if let Some(mut flow) = flows.remove(token) {
registry
.deregister(&mut flow.stream)
.expect("deregister of a registered, owned flow must succeed");
registry.deregister(&mut flow.stream)?;
}
}
}
Ok(())
}
Loading
Loading