Skip to content

Commit 6c74bc2

Browse files
committed
Add Handle::send_keepalive()
In this commit, I add a function to russh's client Handle that allows to manually send a keepalive message to the server. Fixes: #507 Signed-off-by: Uli Schlachter <[email protected]>
1 parent c2fa2df commit 6c74bc2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

russh/src/client/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ pub enum Msg {
193193
GetServerSigAlgs {
194194
reply_channel: oneshot::Sender<Option<Vec<Algorithm>>>,
195195
},
196+
/// Send a keepalive packet to the remote
197+
Keepalive {
198+
want_reply: bool
199+
},
196200
}
197201

198202
impl From<(ChannelId, ChannelMsg)> for Msg {
@@ -819,6 +823,14 @@ impl<H: Handler> Handle<H> {
819823

820824
Ok(())
821825
}
826+
827+
/// Send a keepalive package to the remote peer.
828+
pub async fn send_keepalive(&mut self, want_reply: bool) -> Result<(), Error> {
829+
self.sender
830+
.send(Msg::Keepalive { want_reply })
831+
.await
832+
.map_err(|_| Error::SendError)
833+
}
822834
}
823835

824836
impl<H: Handler> Future for Handle<H> {
@@ -1354,6 +1366,9 @@ impl Session {
13541366
Msg::GetServerSigAlgs { reply_channel } => {
13551367
let _ = reply_channel.send(self.server_sig_algs.clone());
13561368
}
1369+
Msg::Keepalive { want_reply } => {
1370+
let _ = self.send_keepalive(want_reply);
1371+
}
13571372
msg => {
13581373
// should be unreachable, since the receiver only gets
13591374
// messages from methods implemented within russh

0 commit comments

Comments
 (0)