Simplify endpoint outcome state handling

This commit is contained in:
Michael Mikovsky
2026-04-25 20:47:37 -06:00
parent f2c6a54060
commit 31a0bd39b0
19 changed files with 234 additions and 192 deletions
+6 -6
View File
@@ -4,7 +4,7 @@ use std::process::Command;
use std::time::Instant;
use unshell::protocol::tree::{
ChildRoute, Endpoint, Ingress, LeafSpec, LocalEvent, ProtocolEndpoint,
ChildRoute, Endpoint, EndpointOutcome, Ingress, LeafSpec, LocalEvent, ProtocolEndpoint,
};
use unshell::protocol::{CallMessage, PacketHeader, PacketType, decode_frame, encode_packet};
@@ -105,7 +105,7 @@ fn bench_forward_call_receive() -> BenchResult {
let outcome = root
.receive(&Ingress::Local, frame)
.expect("forward receive should work");
black_box(outcome.forward.is_some());
black_box(matches!(outcome, EndpointOutcome::Forward { .. }));
},
)
}
@@ -118,8 +118,8 @@ fn bench_local_call_receive() -> BenchResult {
let outcome = endpoint
.receive(&Ingress::Parent, frame)
.expect("local call should work");
match black_box(outcome.event) {
Some(LocalEvent::Call { .. }) => {}
match black_box(outcome) {
EndpointOutcome::Local(LocalEvent::Call { .. }) => {}
other => panic!("expected local call event, got {other:?}"),
}
},
@@ -134,8 +134,8 @@ fn bench_hook_data_receive() -> BenchResult {
let outcome = host
.receive(&Ingress::Child(path(&["worker"])), frame)
.expect("hook data should work");
match black_box(outcome.event) {
Some(LocalEvent::Data { .. }) => {}
match black_box(outcome) {
EndpointOutcome::Local(LocalEvent::Data { .. }) => {}
other => panic!("expected local data event, got {other:?}"),
}
},
+11 -13
View File
@@ -3,7 +3,7 @@
use std::hint::black_box;
use unshell::protocol::tree::{
ChildRoute, Endpoint, Ingress, LeafSpec, LocalEvent, ProtocolEndpoint,
ChildRoute, Endpoint, EndpointOutcome, Ingress, LeafSpec, LocalEvent, ProtocolEndpoint,
};
use unshell::protocol::{CallMessage, PacketHeader, PacketType, decode_frame, encode_packet};
@@ -94,14 +94,12 @@ pub fn run_forward_call_receive(iterations: usize) -> usize {
let outcome = root
.receive(&Ingress::Local, frame)
.expect("forward receive should work");
let forwarded = outcome
.forward
.as_ref()
.map(|(route, frame)| route_value(*route).wrapping_add(frame.len()))
.unwrap_or_default();
checksum = checksum
.wrapping_add(forwarded)
.wrapping_add(outcome.dropped as usize);
let forwarded = match outcome {
EndpointOutcome::Forward { route, frame } => route_value(route).wrapping_add(frame.len()),
EndpointOutcome::Local(_) => 0,
EndpointOutcome::Dropped => usize::from(true),
};
checksum = checksum.wrapping_add(forwarded);
}
black_box(checksum)
}
@@ -141,8 +139,8 @@ pub fn run_local_call_receive(iterations: usize) -> usize {
let outcome = endpoint
.receive(&Ingress::Parent, frame)
.expect("local call should work");
match outcome.event {
Some(LocalEvent::Call { header, message }) => {
match outcome {
EndpointOutcome::Local(LocalEvent::Call { header, message }) => {
checksum = checksum
.wrapping_add(header.dst_path.len())
.wrapping_add(header.src_path.len())
@@ -194,8 +192,8 @@ pub fn run_hook_data_receive(iterations: usize) -> usize {
let outcome = host
.receive(&Ingress::Child(path(&["worker"])), frame)
.expect("hook data should work");
match outcome.event {
Some(LocalEvent::Data {
match outcome {
EndpointOutcome::Local(LocalEvent::Data {
header, message, ..
}) => {
checksum = checksum
+5 -4
View File
@@ -2,8 +2,9 @@ use std::error::Error;
use std::{convert::Infallible, string::String};
use rkyv::{Archive, Deserialize, Serialize};
use unshell::protocol::tree::{Call, CallLeaf, Ingress, LeafRuntime, ProtocolEndpoint};
use unshell::protocol::tree::{ChildRoute, ConnectionState};
use unshell::protocol::tree::{
Call, CallLeaf, ChildRoute, EndpointOutcome, Ingress, LeafRuntime, ProtocolEndpoint,
};
use unshell::protocol::{PacketType, decode_frame};
use unshell::{Leaf, procedures};
@@ -60,7 +61,7 @@ fn main() -> Result<(), Box<dyn Error>> {
None,
vec![ChildRoute {
path: path(&["agent"]),
state: ConnectionState::Registered,
registered: true,
}],
Vec::new(),
);
@@ -74,7 +75,7 @@ fn main() -> Result<(), Box<dyn Error>> {
text: String::from("hello leaf"),
})?,
)?;
let Some((_, frame)) = controller_outcome.forward else {
let EndpointOutcome::Forward { frame, .. } = controller_outcome else {
return Err("expected controller to forward call".into());
};
+2 -2
View File
@@ -4,7 +4,7 @@ mod remote_shell;
use std::error::Error;
use std::net::TcpListener;
use unshell::protocol::tree::{Endpoint, Ingress, LocalEvent};
use unshell::protocol::tree::{Endpoint, EndpointOutcome, Ingress, LocalEvent};
fn main() -> Result<(), Box<dyn Error>> {
let listener = TcpListener::bind(remote_shell::LISTEN_ADDR)?;
@@ -46,7 +46,7 @@ fn main() -> Result<(), Box<dyn Error>> {
for result in frame_rx {
let frame = result?;
let outcome = endpoint.receive(&Ingress::Child(remote_shell::agent_path()), frame)?;
let Some(event) = outcome.event else {
let EndpointOutcome::Local(event) = outcome else {
continue;
};