diff options
| author | Thomas Linford <tlinford@users.noreply.github.com> | 2022-05-16 21:14:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-16 21:14:57 +0200 |
| commit | e8f955906293fcfe84d73a8af4a3c7f458708d06 (patch) | |
| tree | ce45348a986896bae8db99cab174de5a96169b21 /zellij-server/src/thread_bus.rs | |
| parent | docs(changelog): ansi resize input (diff) | |
| download | sl0ppij-e8f955906293fcfe84d73a8af4a3c7f458708d06.tar.gz sl0ppij-e8f955906293fcfe84d73a8af4a3c7f458708d06.tar.xz sl0ppij-e8f955906293fcfe84d73a8af4a3c7f458708d06.zip | |
fix(pty): paste freeze with large amounts of text (#1383)
add pty writer thread to avoid screen thread blocking on unistd::write
Diffstat (limited to 'zellij-server/src/thread_bus.rs')
| -rw-r--r-- | zellij-server/src/thread_bus.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/zellij-server/src/thread_bus.rs b/zellij-server/src/thread_bus.rs index c7262993..f2fd672e 100644 --- a/zellij-server/src/thread_bus.rs +++ b/zellij-server/src/thread_bus.rs @@ -1,8 +1,8 @@ //! Definitions and helpers for sending and receiving messages between threads. use crate::{ - os_input_output::ServerOsApi, pty::PtyInstruction, screen::ScreenInstruction, - wasm_vm::PluginInstruction, ServerInstruction, + os_input_output::ServerOsApi, pty::PtyInstruction, pty_writer::PtyWriteInstruction, + screen::ScreenInstruction, wasm_vm::PluginInstruction, ServerInstruction, }; use zellij_utils::{channels, channels::SenderWithContext, errors::ErrorContext}; @@ -13,6 +13,7 @@ pub(crate) struct ThreadSenders { pub to_pty: Option<SenderWithContext<PtyInstruction>>, pub to_plugin: Option<SenderWithContext<PluginInstruction>>, pub to_server: Option<SenderWithContext<ServerInstruction>>, + pub to_pty_writer: Option<SenderWithContext<PtyWriteInstruction>>, // this is a convenience for the unit tests // it's not advisable to set it to true in production code pub should_silently_fail: bool, @@ -82,6 +83,22 @@ impl ThreadSenders { self.to_server.as_ref().unwrap().send(instruction) } } + pub fn send_to_pty_writer( + &self, + instruction: PtyWriteInstruction, + ) -> Result<(), channels::SendError<(PtyWriteInstruction, ErrorContext)>> { + if self.should_silently_fail { + let _ = self + .to_pty_writer + .as_ref() + .map(|sender| sender.send(instruction)) + .unwrap_or_else(|| Ok(())); + Ok(()) + } else { + self.to_pty_writer.as_ref().unwrap().send(instruction) + } + } + #[allow(unused)] pub fn silently_fail_on_send(mut self) -> Self { // this is mostly used for the tests, see struct @@ -105,6 +122,7 @@ impl<T> Bus<T> { to_pty: Option<&SenderWithContext<PtyInstruction>>, to_plugin: Option<&SenderWithContext<PluginInstruction>>, to_server: Option<&SenderWithContext<ServerInstruction>>, + to_pty_writer: Option<&SenderWithContext<PtyWriteInstruction>>, os_input: Option<Box<dyn ServerOsApi>>, ) -> Self { Bus { @@ -114,6 +132,7 @@ impl<T> Bus<T> { to_pty: to_pty.cloned(), to_plugin: to_plugin.cloned(), to_server: to_server.cloned(), + to_pty_writer: to_pty_writer.cloned(), should_silently_fail: false, }, os_input: os_input.clone(), @@ -129,6 +148,7 @@ impl<T> Bus<T> { to_pty: None, to_plugin: None, to_server: None, + to_pty_writer: None, should_silently_fail: true, }, os_input: None, |
