A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
wezterm-ssh: drain what libssh already holds before waiting again
RoversXe52fe5f5d6c6
diff --git a/wezterm-ssh/src/channelwrap.rs b/wezterm-ssh/src/channelwrap.rsindex db79dbcd..321c7451 100644--- a/wezterm-ssh/src/channelwrap.rs+++ b/wezterm-ssh/src/channelwrap.rs@@ -69,6 +69,21 @@ impl ChannelWrap {}}+ /// Whether stream `idx` has bytes waiting inside the library, beyond+ /// what a read just took. Unknown for ssh2, which reports false.+ pub fn has_pending(&self, idx: usize) -> bool {+ match self {+ #[cfg(feature = "ssh2")]+ Self::Ssh2(_) => false,++ #[cfg(feature = "libssh-rs")]+ Self::LibSsh(chan) => matches!(+ chan.poll_timeout(idx == 1, Some(std::time::Duration::ZERO)),+ Ok(libssh_rs::PollStatus::AvailableBytes(n)) if n > 0+ ),+ }+ }+pub fn writer(&mut self) -> Box<dyn std::io::Write + '_> {match self {#[cfg(feature = "ssh2")]diff --git a/wezterm-ssh/src/sessioninner.rs b/wezterm-ssh/src/sessioninner.rsindex 82ecfb20..4819b75c 100644--- a/wezterm-ssh/src/sessioninner.rs+++ b/wezterm-ssh/src/sessioninner.rs@@ -687,31 +687,46 @@ impl SessionInner {if out.fd.is_none() {continue;}- let current_len = out.buf.len();- let room = out.buf.capacity() - current_len;- if room == 0 {- continue;- }- match read_into_buf(&mut chan.channel.reader(idx), &mut out.buf) {- Ok(progress) => made_progress |= progress,- Err(err) => {- if out.buf.is_empty() {- log::trace!(- "Failed to read data from channel {} stream {}: {:#}, closing pipe",- id,- idx,- err- );- out.fd.take();+ // Drain what the channel holds while there is room. libssh+ // takes in a whole packet at a time, so after one read the+ // socket can show nothing more while the channel still holds+ // plenty; one read per wakeup left the rest to the next one,+ // which came only when the socket had more or poll timed out+ // -- and that timeout doubles, so a busy stream waited longer+ // at every turn.+ loop {+ if out.buf.len() == out.buf.capacity() {+ break;+ }+ let read = read_into_buf(&mut chan.channel.reader(idx), &mut out.buf);+ match read {+ Ok(true) => {made_progress = true;- } else {- log::trace!(- "Failed to read data from channel {} stream {}: {:#}, but \- still have some buffer to drain",- id,- idx,- err- );+ if !chan.channel.has_pending(idx) {+ break;+ }+ }+ Ok(false) => break,+ Err(err) => {+ if out.buf.is_empty() {+ log::trace!(+ "Failed to read data from channel {} stream {}: {:#}, closing pipe",+ id,+ idx,+ err+ );+ out.fd.take();+ made_progress = true;+ } else {+ log::trace!(+ "Failed to read data from channel {} stream {}: {:#}, but \+ still have some buffer to drain",+ id,+ idx,+ err+ );+ }+ break;}}}