From 29e484351791e1dfef798528096697c7f6b5a342 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 28 Oct 2019 08:11:06 -0700 Subject: [PATCH] move away from explicit executor.clone_executor() calls call the gui_executor() function instead --- src/frontend/muxserver/mod.rs | 2 +- src/mux/mod.rs | 7 ++-- src/server/listener.rs | 79 +++++++++++++---------------------- 3 files changed, 32 insertions(+), 56 deletions(-) diff --git a/src/frontend/muxserver/mod.rs b/src/frontend/muxserver/mod.rs index b75876b69..069cad35e 100644 --- a/src/frontend/muxserver/mod.rs +++ b/src/frontend/muxserver/mod.rs @@ -43,7 +43,7 @@ impl MuxServerFrontEnd { let (tx, rx) = mpsc::channel(); if start_listener { - spawn_listener(mux.config(), Box::new(MuxExecutor { tx: tx.clone() }))?; + spawn_listener(mux.config())?; } Ok(Rc::new(Self { tx, rx })) } diff --git a/src/mux/mod.rs b/src/mux/mod.rs index 18240c438..e920816f1 100644 --- a/src/mux/mod.rs +++ b/src/mux/mod.rs @@ -9,7 +9,7 @@ use failure::{bail, format_err, Error, Fallible}; use failure_derive::*; use log::{debug, error}; use portable_pty::ExitStatus; -use promise::{Executor, Future}; +use promise::Future; use std::cell::{Ref, RefCell, RefMut}; use std::collections::HashMap; use std::io::Read; @@ -46,7 +46,6 @@ pub struct Mux { } fn read_from_tab_pty(config: Arc, tab_id: TabId, mut reader: Box) { - let executor = gui_executor().expect("gui_executor was not registered yet!?"); const BUFSIZE: usize = 32 * 1024; let mut buf = [0; BUFSIZE]; @@ -69,7 +68,7 @@ fn read_from_tab_pty(config: Arc, tab_id: TabId, mut reader: Box { lim.blocking_admittance_check(size as u32); let data = buf[0..size].to_vec(); - Future::with_executor(executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); if let Some(tab) = mux.get_tab(tab_id) { tab.advance_bytes( @@ -85,7 +84,7 @@ fn read_from_tab_pty(config: Arc, tab_id: TabId, mut reader: Box, } impl LocalListener { - pub fn new(listener: UnixListener, executor: Box) -> Self { - Self { listener, executor } + pub fn new(listener: UnixListener) -> Self { + Self { listener } } fn run(&mut self) { for stream in self.listener.incoming() { match stream { Ok(stream) => { - let executor = self.executor.clone_executor(); - Future::with_executor(executor.clone_executor(), move || { - let mut session = ClientSession::new(stream, executor); + Future::with_executor(gui_executor().unwrap(), move || { + let mut session = ClientSession::new(stream); thread::spawn(move || session.run()); Ok(()) }); @@ -183,12 +182,12 @@ mod not_ossl { match stream { Ok(stream) => { stream.set_nodelay(true).ok(); - let executor = self.executor.clone_executor(); + let executor = gui_executor().unwrap(); let acceptor = self.acceptor.clone(); match acceptor.accept(stream) { Ok(stream) => { - Future::with_executor(executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mut session = ClientSession::new(stream, executor); thread::spawn(move || session.run()); Ok(()) @@ -250,19 +249,13 @@ mod ossl { struct OpenSSLNetListener { acceptor: Arc, listener: TcpListener, - executor: Box, } impl OpenSSLNetListener { - pub fn new( - listener: TcpListener, - acceptor: SslAcceptor, - executor: Box, - ) -> Self { + pub fn new(listener: TcpListener, acceptor: SslAcceptor) -> Self { Self { listener, acceptor: Arc::new(acceptor), - executor, } } @@ -318,7 +311,6 @@ mod ossl { match stream { Ok(stream) => { stream.set_nodelay(true).ok(); - let executor = self.executor.clone_executor(); let acceptor = self.acceptor.clone(); match acceptor.accept(stream) { @@ -328,8 +320,8 @@ mod ossl { break; } - Future::with_executor(executor.clone_executor(), move || { - let mut session = ClientSession::new(stream, executor); + Future::with_executor(gui_executor().unwrap(), move || { + let mut session = ClientSession::new(stream); thread::spawn(move || session.run()); Ok(()) }); @@ -350,7 +342,6 @@ mod ossl { pub fn spawn_tls_listener( _config: &Arc, - executor: Box, tls_server: &TlsDomainServer, ) -> Result<(), Error> { openssl::init(); @@ -396,7 +387,6 @@ mod ossl { ) })?, acceptor, - executor, ); thread::spawn(move || { net_listener.run(); @@ -407,7 +397,6 @@ mod ossl { pub struct ClientSession { stream: S, - executor: Box, surfaces_by_tab: Arc>>, to_write_rx: PollableReceiver, to_write_tx: PollableSender, @@ -594,14 +583,13 @@ impl<'a> term::TerminalHost for BufferedTerminalHost<'a> { } impl ClientSession { - fn new(stream: S, executor: Box) -> Self { + fn new(stream: S) -> Self { let (to_write_tx, to_write_rx) = pollable_channel().expect("failed to create pollable_channel"); let mux = Mux::get().expect("to be running on gui thread"); let mux_rx = mux.subscribe().expect("Mux::subscribe to succeed"); Self { stream, - executor, surfaces_by_tab: Arc::new(Mutex::new(HashMap::new())), to_write_rx, to_write_tx, @@ -644,7 +632,7 @@ impl ClientSession { for tab_id in tabs_to_output.drain() { let surfaces = Arc::clone(&self.surfaces_by_tab); let sender = self.to_write_tx.clone(); - Future::with_executor(self.executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); let tab = mux .get_tab(tab_id) @@ -698,7 +686,7 @@ impl ClientSession { match pdu { Pdu::Ping(Ping {}) => Future::ok(Pdu::Pong(Pong {})), Pdu::ListTabs(ListTabs {}) => { - Future::with_executor(self.executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); let mut tabs = vec![]; for window_id in mux.iter_windows().into_iter() { @@ -726,7 +714,7 @@ impl ClientSession { Pdu::WriteToTab(WriteToTab { tab_id, data }) => { let surfaces = Arc::clone(&self.surfaces_by_tab); let sender = self.to_write_tx.clone(); - Future::with_executor(self.executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); let tab = mux .get_tab(tab_id) @@ -739,7 +727,7 @@ impl ClientSession { Pdu::SendPaste(SendPaste { tab_id, data }) => { let surfaces = Arc::clone(&self.surfaces_by_tab); let sender = self.to_write_tx.clone(); - Future::with_executor(self.executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); let tab = mux .get_tab(tab_id) @@ -751,7 +739,7 @@ impl ClientSession { } Pdu::Resize(Resize { tab_id, size }) => { - Future::with_executor(self.executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); let tab = mux .get_tab(tab_id) @@ -764,7 +752,7 @@ impl ClientSession { Pdu::SendKeyDown(SendKeyDown { tab_id, event }) => { let surfaces = Arc::clone(&self.surfaces_by_tab); let sender = self.to_write_tx.clone(); - Future::with_executor(self.executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); let tab = mux .get_tab(tab_id) @@ -777,7 +765,7 @@ impl ClientSession { Pdu::SendMouseEvent(SendMouseEvent { tab_id, event }) => { let surfaces = Arc::clone(&self.surfaces_by_tab); let sender = self.to_write_tx.clone(); - Future::with_executor(self.executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); let tab = mux .get_tab(tab_id) @@ -800,7 +788,7 @@ impl ClientSession { }) } - Pdu::Spawn(spawn) => Future::with_executor(self.executor.clone_executor(), move || { + Pdu::Spawn(spawn) => Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); let domain = mux.get_domain(spawn.domain_id).ok_or_else(|| { format_err!("domain {} not found on this server", spawn.domain_id) @@ -825,7 +813,7 @@ impl ClientSession { Pdu::GetTabRenderChanges(GetTabRenderChanges { tab_id, .. }) => { let surfaces = Arc::clone(&self.surfaces_by_tab); let sender = self.to_write_tx.clone(); - Future::with_executor(self.executor.clone_executor(), move || { + Future::with_executor(gui_executor().unwrap(), move || { let mux = Mux::get().unwrap(); let tab = mux .get_tab(tab_id) @@ -926,36 +914,25 @@ fn safely_create_sock_path(unix_dom: &UnixDomain) -> Result } #[cfg(any(feature = "openssl", unix))] -fn spawn_tls_listener( - config: &Arc, - executor: Box, - tls_server: &TlsDomainServer, -) -> Fallible<()> { - ossl::spawn_tls_listener(config, executor, tls_server) +fn spawn_tls_listener(config: &Arc, tls_server: &TlsDomainServer) -> Fallible<()> { + ossl::spawn_tls_listener(config, tls_server) } #[cfg(not(any(feature = "openssl", unix)))] -fn spawn_tls_listener( - config: &Arc, - executor: Box, - tls_server: &TlsDomainServer, -) -> Fallible<()> { - not_ossl::spawn_tls_listener(config, executor, tls_server) +fn spawn_tls_listener(config: &Arc, tls_server: &TlsDomainServer) -> Fallible<()> { + not_ossl::spawn_tls_listener(config, tls_server) } -pub fn spawn_listener(config: &Arc, executor: Box) -> Fallible<()> { +pub fn spawn_listener(config: &Arc) -> Fallible<()> { for unix_dom in &config.unix_domains { - let mut listener = LocalListener::new( - safely_create_sock_path(unix_dom)?, - executor.clone_executor(), - ); + let mut listener = LocalListener::new(safely_create_sock_path(unix_dom)?); thread::spawn(move || { listener.run(); }); } for tls_server in &config.tls_servers { - spawn_tls_listener(config, executor.clone_executor(), tls_server)?; + spawn_tls_listener(config, tls_server)?; } Ok(()) }