Skip to content

Commit 1e96032

Browse files
authored
Merge pull request #16 from guswynn/fix-tokio-read
fix usage of ReadBuf in tokio AsyncRead impls
2 parents c05dee5 + 5b33f5a commit 1e96032

File tree

7 files changed

+36
-2
lines changed

7 files changed

+36
-2
lines changed

async-ssh2-lite/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ default = []
1818
vendored-openssl = ["ssh2/vendored-openssl"]
1919

2020
_integration_tests = []
21+
_integration_tests_tokio_ext = []
2122

2223
[dependencies]
2324
ssh2 = { version = "0.9", default-features = false }

async-ssh2-lite/src/channel.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,20 @@ mod impl_tokio {
338338
let sess = this.sess.clone();
339339
let inner = &mut this.inner;
340340

341-
this.stream
342-
.poll_read_with(cx, || inner.read(buf.filled_mut()).map(|_| {}), &sess)
341+
this.stream.poll_read_with(
342+
cx,
343+
|| {
344+
let size = inner.read(buf.initialize_unfilled());
345+
match size {
346+
Ok(size) => {
347+
buf.advance(size);
348+
Ok(())
349+
}
350+
Err(e) => Err(e),
351+
}
352+
},
353+
&sess,
354+
)
343355
}
344356
}
345357

async-ssh2-lite/tests/integration_tests/channel__exec.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
use std::error;
44

55
use async_ssh2_lite::{AsyncSession, AsyncSessionStream};
6+
#[cfg(not(feature = "_integration_tests_tokio_ext"))]
67
use futures_util::AsyncReadExt as _;
8+
#[cfg(feature = "_integration_tests_tokio_ext")]
9+
use tokio::io::AsyncReadExt as _;
710

811
use super::{
912
helpers::get_connect_addr, session__userauth_pubkey::__run__session__userauth_pubkey_file,
@@ -54,5 +57,13 @@ async fn __run__session__channel_session__exec<S: AsyncSessionStream + Send + Sy
5457
channel.close().await?;
5558
println!("exec date exit_status:{}", channel.exit_status()?);
5659

60+
let mut channel = session.channel_session().await?;
61+
channel.exec("head -c 16354 /dev/random").await?;
62+
let mut b = vec![];
63+
channel.read_to_end(&mut b).await?;
64+
assert_eq!(b.len(), 16354);
65+
channel.close().await?;
66+
println!("exec head exit_status:{}", channel.exit_status()?);
67+
5768
Ok(())
5869
}

async-ssh2-lite/tests/integration_tests/remote_port_forwarding.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use std::{error, net::SocketAddr};
44

55
use async_ssh2_lite::{util::ConnectInfo, AsyncSession};
66
use futures_util::future::join_all;
7+
#[cfg(not(feature = "_integration_tests_tokio_ext"))]
78
use futures_util::AsyncReadExt as _;
9+
#[cfg(feature = "_integration_tests_tokio_ext")]
10+
use tokio::io::AsyncReadExt as _;
811

912
use super::{
1013
helpers::{get_connect_addr, get_listen_addr, is_internal_test_openssh_server},

async-ssh2-lite/tests/integration_tests/session__channel_forward_listen.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use std::error;
44

55
use async_ssh2_lite::{ssh2::ErrorCode, AsyncSession, AsyncSessionStream, Error};
66
use futures_util::future::join_all;
7+
#[cfg(not(feature = "_integration_tests_tokio_ext"))]
78
use futures_util::{AsyncReadExt as _, AsyncWriteExt as _};
9+
#[cfg(feature = "_integration_tests_tokio_ext")]
10+
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
811

912
use super::{
1013
helpers::get_connect_addr, session__userauth_pubkey::__run__session__userauth_pubkey_file,

async-ssh2-lite/tests/integration_tests/session__scp_send_and_scp_recv.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::{
66
};
77

88
use async_ssh2_lite::{AsyncSession, AsyncSessionStream};
9+
#[cfg(not(feature = "_integration_tests_tokio_ext"))]
910
use futures_util::{AsyncReadExt as _, AsyncWriteExt as _};
11+
#[cfg(feature = "_integration_tests_tokio_ext")]
12+
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
1013
use rand::{distributions::Alphanumeric, thread_rng, Rng as _};
1114
use uuid::Uuid;
1215

async-ssh2-lite/tests/run_integration_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export SSH_USERNAME="linuxserver.io"
2323
export SSH_PASSWORD="password"
2424

2525
${run} ${version} ${listen_port} "cd ${script_path_root}..; cargo test -p async-ssh2-lite --features _integration_tests,async-io,tokio -- --nocapture"
26+
${run} ${version} ${listen_port} "cd ${script_path_root}..; cargo test -p async-ssh2-lite --features _integration_tests,_integration_tests_tokio_ext,async-io,tokio -- --nocapture"

0 commit comments

Comments
 (0)