From 97f3e3083bf9fe6a0e22bd76f1106c133df5621c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 2 Oct 2019 10:32:48 -0400 Subject: add stub sigwinch handler --- Cargo.lock | 1 + Cargo.toml | 1 + src/cmd/cast.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 93c919c..2cec18a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -581,6 +581,7 @@ dependencies = [ "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-pty-process 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-signal 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "twoway 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 4af5b09..b58e558 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ mio = "0.6" snafu = { version = "0.5", features = ["futures-01"] } tokio = "0.1" tokio-pty-process = "0.4" +tokio-signal = "0.2" twoway = "0.2" uuid = { version = "0.7", features = ["v4"] } diff --git a/src/cmd/cast.rs b/src/cmd/cast.rs index e7f015f..3715ebf 100644 --- a/src/cmd/cast.rs +++ b/src/cmd/cast.rs @@ -1,5 +1,6 @@ use futures::future::Future as _; use futures::stream::Stream as _; +use snafu::futures01::stream::StreamExt as _; use snafu::ResultExt as _; use tokio::io::AsyncWrite as _; @@ -19,6 +20,9 @@ pub enum Error { #[snafu(display("communication with server failed: {}", source))] Client { source: crate::client::Error }, + + #[snafu(display("SIGWINCH handler failed: {}", source))] + SigWinchHandler { source: std::io::Error }, } pub type Result = std::result::Result; @@ -75,6 +79,8 @@ struct CastSession { client: crate::client::Client, process: crate::process::Process, stdout: tokio::io::Stdout, + winches: + Box + Send>, buffer: crate::term::Buffer, sent_local: usize, sent_remote: usize, @@ -97,10 +103,17 @@ impl CastSession { ); let process = crate::process::Process::new(cmd, args).context(Spawn)?; + let winches = tokio_signal::unix::Signal::new( + tokio_signal::unix::libc::SIGWINCH, + ) + .flatten_stream() + .map(|_| ()) + .context(SigWinchHandler); Ok(Self { client, process, stdout: tokio::io::stdout(), + winches: Box::new(winches), buffer: crate::term::Buffer::new(), sent_local: 0, sent_remote: 0, @@ -128,6 +141,7 @@ impl CastSession { &Self::poll_write_terminal, &Self::poll_flush_terminal, &Self::poll_write_server, + &Self::poll_sigwinch, ]; // this should never return Err, because we don't want server @@ -253,6 +267,19 @@ impl CastSession { Ok(crate::component_future::Poll::DidWork) } + + fn poll_sigwinch(&mut self) -> Result> { + match self.winches.poll()? { + futures::Async::Ready(Some(_)) => { + // TODO + Ok(crate::component_future::Poll::DidWork) + } + futures::Async::Ready(None) => unreachable!(), + futures::Async::NotReady => { + Ok(crate::component_future::Poll::NotReady) + } + } + } } #[must_use = "futures do nothing unless polled"] -- cgit v1.2.3-54-g00ecf