Files
unshell/examples/protocol/remote_shell_endpoint.rs
T

35 lines
1.0 KiB
Rust
Raw Normal View History

2026-04-25 14:46:59 -06:00
#[path = "support/remote_shell_common.rs"]
2026-04-25 14:41:00 -06:00
mod common;
use std::error::Error;
use std::net::TcpStream;
2026-04-25 15:35:08 -06:00
use std::sync::mpsc::RecvTimeoutError;
2026-04-25 14:41:00 -06:00
use std::time::Duration;
2026-04-25 15:35:08 -06:00
use unshell::protocol::tree::Ingress;
2026-04-25 14:41:00 -06:00
fn main() -> Result<(), Box<dyn Error>> {
let mut stream = TcpStream::connect(common::LISTEN_ADDR)?;
let frame_rx = common::spawn_frame_reader(stream.try_clone()?);
2026-04-25 15:35:08 -06:00
let mut runtime = common::build_agent_runtime();
2026-04-25 14:41:00 -06:00
println!("connected to controller at {}", common::LISTEN_ADDR);
loop {
match frame_rx.recv_timeout(Duration::from_millis(25)) {
Ok(result) => {
let frame = result?;
2026-04-25 15:35:08 -06:00
let outcome = runtime.receive(&Ingress::Parent, frame)?;
common::write_frames(&mut stream, &outcome.frames)?;
2026-04-25 14:41:00 -06:00
}
Err(RecvTimeoutError::Timeout) => {}
Err(RecvTimeoutError::Disconnected) => break,
}
2026-04-25 15:35:08 -06:00
let outcome = runtime.poll()?;
common::write_frames(&mut stream, &outcome.frames)?;
2026-04-25 14:41:00 -06:00
}
Ok(())
}