Skip to content

Commit 6a6fa80

Browse files
committed
make ChannelCloseOnDrop async
1 parent ef50df9 commit 6a6fa80

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

russh/src/channels/channel_stream.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ use super::{ChannelId, ChannelMsg};
1010
/// AsyncRead/AsyncWrite wrapper for SSH Channels
1111
pub struct ChannelStream<S>
1212
where
13-
S: From<(ChannelId, ChannelMsg)> + 'static,
13+
S: From<(ChannelId, ChannelMsg)> + Send + 'static,
1414
{
1515
tx: ChannelTx<S>,
1616
rx: ChannelRx<ChannelCloseOnDrop<S>>,
1717
}
1818

1919
impl<S> ChannelStream<S>
2020
where
21-
S: From<(ChannelId, ChannelMsg)>,
21+
S: From<(ChannelId, ChannelMsg)> + Send,
2222
{
2323
pub(super) fn new(tx: ChannelTx<S>, rx: ChannelRx<ChannelCloseOnDrop<S>>) -> Self {
2424
Self { tx, rx }
@@ -27,7 +27,7 @@ where
2727

2828
impl<S> AsyncRead for ChannelStream<S>
2929
where
30-
S: From<(ChannelId, ChannelMsg)>,
30+
S: From<(ChannelId, ChannelMsg)> + Send,
3131
{
3232
fn poll_read(
3333
mut self: Pin<&mut Self>,

russh/src/channels/io/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@ pub use tx::ChannelTx;
99
use crate::{Channel, ChannelId, ChannelMsg, ChannelReadHalf};
1010

1111
#[derive(Debug)]
12-
pub struct ChannelCloseOnDrop<S: From<(ChannelId, ChannelMsg)>>(pub Channel<S>);
13-
impl<S: From<(ChannelId, ChannelMsg)>> Borrow<ChannelReadHalf> for ChannelCloseOnDrop<S> {
12+
pub struct ChannelCloseOnDrop<S: From<(ChannelId, ChannelMsg)> + Send + 'static>(pub Channel<S>);
13+
14+
impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Borrow<ChannelReadHalf>
15+
for ChannelCloseOnDrop<S>
16+
{
1417
fn borrow(&self) -> &ChannelReadHalf {
1518
&self.0.read_half
1619
}
1720
}
18-
impl<S: From<(ChannelId, ChannelMsg)>> BorrowMut<ChannelReadHalf> for ChannelCloseOnDrop<S> {
21+
22+
impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> BorrowMut<ChannelReadHalf>
23+
for ChannelCloseOnDrop<S>
24+
{
1925
fn borrow_mut(&mut self) -> &mut ChannelReadHalf {
2026
&mut self.0.read_half
2127
}
2228
}
23-
impl<S: From<(ChannelId, ChannelMsg)>> Drop for ChannelCloseOnDrop<S> {
29+
30+
impl<S: From<(ChannelId, ChannelMsg)> + Send + 'static> Drop for ChannelCloseOnDrop<S> {
2431
fn drop(&mut self) {
25-
let Self(channel) = self;
26-
let _ = channel
27-
.write_half
28-
.sender
29-
.try_send((channel.write_half.id, ChannelMsg::Close).into());
32+
let id = self.0.write_half.id;
33+
let sender = self.0.write_half.sender.clone();
34+
tokio::spawn(async move {
35+
let _ = sender.send((id, ChannelMsg::Close).into()).await;
36+
});
3037
}
3138
}

0 commit comments

Comments
 (0)