bk-rs / ssh-rs

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

can I use a BufReader? #18

Closed joshbenz closed 1 year ago

joshbenz commented 2 years ago

Forgive me if this is a stupid question, but is it possible to wrap an AsyncChannel in a futures::io::BufReader? At first glance, it looks like it should work right? My goal is to use https://crates.io/crates/nom-bufreader but I haven't gotten it to work yet (i get an error). So I was just wondering if it's possible and if so, could I get an example?

Thank you for your work on this crate!

Also this is the error I get panicked at 'internal error: entered unreachable code: reader indicated readiness but then returned pending', /home/jbenz/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.24/src/io/fill_buf.rs:41:21

This is the point that I get to

                let mut chan = sess.channel_session().await?;
                chan.request_pty("xterm", None, Some((80, 24, 0, 0))).await?;
                chan.shell().await?;
                chan.write(b"environment no more\nfile dir\n").await?;
                let mut reader = BufReader::new(chan.compat());
                let m = reader.parse(Self::method).await;
joshbenz commented 2 years ago

So I just discovered that sometimes it works and sometimes it doesn't. Also I am using an AsyncStream<TokioTcpStream> now. I am not sure if the issue is with AsyncStream<> or if it is with nom-bufreader crate.

vkill commented 2 years ago

hi @jbenz1 , I think the issue is with AsyncStream<>. Same as https://github.com/bk-rs/ssh-rs/issues/17 .

vkill commented 2 years ago

And you can try nom_bufreader::bufreader::BufReader with ssh2::Channel . I guess it also sometimes working and sometimes not working.

joshbenz commented 2 years ago

ah ok. I'll try with ssh2::Channel and sync nom_bufreader when I get a chance, just to verify the behavior. I'm thinking I won't be using this nom_bufreader now anyways, at least not yet. Thanks @vkill !