mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Split remote shell leaf module
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#[path = "support/remote_shell_common.rs"]
|
||||
mod common;
|
||||
#[path = "../../src/leaf/remote_shell/mod.rs"]
|
||||
mod remote_shell;
|
||||
|
||||
use std::error::Error;
|
||||
use std::net::TcpStream;
|
||||
@@ -9,25 +9,25 @@ use std::time::Duration;
|
||||
use unshell::protocol::tree::Ingress;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut stream = TcpStream::connect(common::LISTEN_ADDR)?;
|
||||
let frame_rx = common::spawn_frame_reader(stream.try_clone()?);
|
||||
let mut runtime = common::build_agent_runtime();
|
||||
let mut stream = TcpStream::connect(remote_shell::LISTEN_ADDR)?;
|
||||
let frame_rx = remote_shell::spawn_frame_reader(stream.try_clone()?);
|
||||
let mut runtime = remote_shell::build_agent_runtime();
|
||||
|
||||
println!("connected to controller at {}", common::LISTEN_ADDR);
|
||||
println!("connected to controller at {}", remote_shell::LISTEN_ADDR);
|
||||
|
||||
loop {
|
||||
match frame_rx.recv_timeout(Duration::from_millis(25)) {
|
||||
Ok(result) => {
|
||||
let frame = result?;
|
||||
let outcome = runtime.receive(&Ingress::Parent, frame)?;
|
||||
common::write_frames(&mut stream, &outcome.frames)?;
|
||||
remote_shell::write_frames(&mut stream, &outcome.frames)?;
|
||||
}
|
||||
Err(RecvTimeoutError::Timeout) => {}
|
||||
Err(RecvTimeoutError::Disconnected) => break,
|
||||
}
|
||||
|
||||
let outcome = runtime.poll()?;
|
||||
common::write_frames(&mut stream, &outcome.frames)?;
|
||||
remote_shell::write_frames(&mut stream, &outcome.frames)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user