From 884fa016cc3555d0e921018a0d557df5df7a6847 Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Sun, 29 Oct 2023 19:41:54 -0700 Subject: [PATCH 1/2] refactor: await r/w stream close instead of proc exit --- client/session.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/client/session.rs b/client/session.rs index 1753640..47732cf 100644 --- a/client/session.rs +++ b/client/session.rs @@ -13,7 +13,6 @@ use sesh_proto::{ sesh_cli_server::SeshCliServer, sesh_kill_request::Session, sesh_resize_request, SeshResizeRequest, SeshStartRequest, WinSize, }; -use sesh_shared::term::process_exit; use termion::color::{self, Fg}; use termion::{raw::IntoRawMode, screen::IntoAlternateScreen}; use tokio::sync::broadcast; @@ -67,8 +66,10 @@ impl Ctx { exit: (tx, rx), }) } +} - fn copy(&self) -> Self { +impl Clone for Ctx { + fn clone(&self) -> Self { Ctx { client: self.client.clone(), exit: (self.exit.0.clone(), self.exit.0.subscribe()), @@ -100,8 +101,6 @@ async fn exec_session( .write_all(format!("\x1B]0;{}\x07", program).as_bytes()) .await?; - let mut input = tokio::io::stdin(); - let sock = PathBuf::from(&socket); let sock_dir = sock .parent() @@ -127,14 +126,14 @@ async fn exec_session( .into_split(); // Reads process output from the server and writes it to the terminal - let r_handle = tokio::task::spawn({ + let mut r_handle = tokio::task::spawn({ let exit = ctx.exit.0.subscribe(); async move { let mut packet = [0; 4096]; while exit.is_empty() { let bytes = r_stream.read(&mut packet).await?; if bytes == 0 { - continue; + break; } output .write_all(&packet[..bytes]) @@ -147,10 +146,11 @@ async fn exec_session( }); // Reads terminal input and sends it to the server to be handled by the process. - let w_handle = tokio::task::spawn({ - let ctx = ctx.copy(); + let mut w_handle = tokio::task::spawn({ + let ctx = ctx.clone(); let name = name.clone(); async move { + let mut input = tokio::io::stdin(); while ctx.exit.1.is_empty() { let mut packet = [0; 4096]; @@ -197,7 +197,7 @@ async fn exec_session( tokio::task::spawn({ let name = name.clone(); - let mut ctx = ctx.copy(); + let mut ctx = ctx.clone(); async move { let mut signal = signal(SignalKind::window_change())?; loop { @@ -229,11 +229,12 @@ async fn exec_session( let mut alarm = signal(SignalKind::alarm())?; let exit = tokio::select! { kind = exit_rx.recv() => kind.unwrap_or(ExitKind::Quit), - _ = process_exit(pid) => ExitKind::Quit, _ = quit.recv() => ExitKind::Quit, _ = interrupt.recv() => ExitKind::Quit, _ = terminate.recv() => ExitKind::Quit, _ = alarm.recv() => ExitKind::Quit, + _ = &mut r_handle => ExitKind::Quit, + _ = &mut w_handle => ExitKind::Quit, }; tokio::fs::remove_file(&client_server_sock).await.ok(); From e5cba16c02732f3cf4788b41284cc7e7869872d2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 02:42:39 +0000 Subject: [PATCH 2/2] chore(main): release 0.2.0 --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b50245..e4db0b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [0.2.0](https://github.com/willothy/sesh/compare/v0.1.12...v0.2.0) (2023-10-30) + + +### Features + +* SessionList with id / name lookup ([84cd7bd](https://github.com/willothy/sesh/commit/84cd7bd5a8ffcf299314dc80f32ad8415e3efb4d)) + + +### Performance Improvements + +* reduce socket check delay when spawning server ([cb22456](https://github.com/willothy/sesh/commit/cb224561bc103a35343984727ea1cda16f6b1aa9)) + ## [0.1.12](https://github.com/willothy/sesh/compare/v0.1.11...v0.1.12) (2023-10-27)