diff --git a/russh/src/channels/mod.rs b/russh/src/channels/mod.rs index aee70c3f..13121143 100644 --- a/russh/src/channels/mod.rs +++ b/russh/src/channels/mod.rs @@ -1,5 +1,6 @@ -use std::sync::Arc; +use std::{pin::Pin, sync::Arc}; +use futures::{Future, FutureExt as _}; use russh_cryptovec::CryptoVec; use tokio::io::{AsyncRead, AsyncWrite}; use tokio::sync::mpsc::{Sender, UnboundedReceiver}; @@ -318,6 +319,26 @@ impl + Send + Sync + 'static> Channel { pub async fn close(&self) -> Result<(), Error> { self.send_msg(ChannelMsg::Close).await } + /// Get a `FnOnce` that can be used to send a signal through this channel + pub fn get_signal_sender( + &self, + ) -> impl FnOnce(Sig) -> Pin> + std::marker::Send>> + { + let sender = self.sender.clone(); + let id = self.id; + + move |signal| { + async move { + sender + .send((id, ChannelMsg::Signal { signal }).into()) + .await + .map_err(|_| Error::SendError)?; + + Ok(()) + } + .boxed() + } + } async fn send_msg(&self, msg: ChannelMsg) -> Result<(), Error> { self.sender