async-ssh2 icon indicating copy to clipboard operation
async-ssh2 copied to clipboard

Blocking on stream.read_to_string()

Open 0xdeafbeef opened this issue 5 years ago • 3 comments

Looks like there is no way to read stream.

channel
        .stream(0)
        .read_to_string(&mut channel_buffer)
        .map_err(|e| Error::msg(format!("Error reading result of work: {}", e)))?;

"Error reading result of work: would block"

0xdeafbeef avatar Aug 03 '20 09:08 0xdeafbeef

Chaning it to

let mut command_stdout = reader(channel.stream(0));

    command_stdout
        .read_to_string(&mut channel_buffer)
        .await
        .map_err(|e| Error::msg(format!("Error reading result of work: {}", e)))?;

also doesn't help :(

0xdeafbeef avatar Aug 03 '20 09:08 0xdeafbeef

https://github.com/0xdeafbeef/async-ssh2 This stupid hack works, but better solution exists

0xdeafbeef avatar Aug 03 '20 12:08 0xdeafbeef

I also hit this read_to_string() issue. My solution is to loop on the basic read method of AsyncRead trait with a fixed buffer. Don't know which point break the AsyncReadExt read_to_string derived implementation.

jason-ni avatar Nov 16 '20 02:11 jason-ni