Chunk terminal output below MTU
This commit is contained in:
+18
-5
@@ -7,6 +7,12 @@ use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
// Keep live terminal output comfortably below common path MTUs after Dosh's
|
||||
// protocol header, AEAD tag, UDP/IP headers, and bincode framing. Full-screen
|
||||
// TUIs often write several KiB on the first draw; sending that as one UDP
|
||||
// datagram can fragment and vanish, leaving only a blank alternate screen.
|
||||
const PTY_OUTPUT_CHUNK_BYTES: usize = 1024;
|
||||
|
||||
/// Backing for a PTY master held by the server.
|
||||
///
|
||||
/// `Owned` means this process spawned the shell as a child and is responsible
|
||||
@@ -264,11 +270,13 @@ fn spawn_reader_thread(
|
||||
break;
|
||||
}
|
||||
Ok(n) => {
|
||||
let _ = tx.send(PtyOutput {
|
||||
session: reader_session.clone(),
|
||||
bytes: buf[..n].to_vec(),
|
||||
exited: false,
|
||||
});
|
||||
for chunk in buf[..n].chunks(PTY_OUTPUT_CHUNK_BYTES) {
|
||||
let _ = tx.send(PtyOutput {
|
||||
session: reader_session.clone(),
|
||||
bytes: chunk.to_vec(),
|
||||
exited: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
let _ = tx.send(PtyOutput {
|
||||
@@ -297,4 +305,9 @@ mod tests {
|
||||
assert!(!terminfo_available("definitely-not-a-real-terminal-xyz"));
|
||||
assert!(!terminfo_available(""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pty_output_chunk_size_stays_mtu_safe() {
|
||||
assert!(PTY_OUTPUT_CHUNK_BYTES <= 1200);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user