bk-rs / ssh-rs

https://docs.rs/async-ssh2-lite
Apache License 2.0
56 stars 21 forks source link

Keep-alives don't work #49

Open kyrias opened 1 month ago

kyrias commented 1 month ago

Based on the API one would expect that calling connect with a SessionConfiguration that has set_keepalive set with an interval above 0 to result in keep-alives being automatically issued. However as per the libssh2 docs:

Note that non-blocking applications are responsible for sending the keepalive messages using libssh2_keepalive_send.

(As an aside, it's unfortunate that the ssh2 crate's docs doesn't include this note.)

It would be nice if the async-ssh2-lite crate implemented its own keep-alive support to make the above option function.

vkill commented 1 month ago

Hi @kyrias Is it possible to implement it yourself? P.S. I have not tested the following code, but this is what it means

{
  let session = session.clone();
  tokio::spawn(async move {
    loop {
      let n = session.keepalive_send().await.unwrap();
      tokio::time::sleep(tokio::time::Duration::from_secs(n)).await;
    }
  }
}