Error when calling more than once method of AdbTcpConnection with the same object
Description
If I call more than once adb's commands with the same AdbTcpConnection, I got a error message.
Error: IOError(Error { kind: UnexpectedEof, message: "failed to fill whole buffer" })
It's the fact of "reusing" the same object to run adb commands which used tcp steam to retrieved the result from adb server. Maybe the buffer used by tcp stream is not cleared correctly, but I'm not good enough with Rust to know how it's handled. Anyway, I think it's must be possible to not create a new connection each times that you called a method.
Reproducible Example
Here a simple example that call 2 times in a row the adb command "version" which produce error (I used command "version" for simplicity's sake but it's the same resul, regardless of the method used)
cargo.toml
[package]
name = "adb_example"
version = "0.1.0"
edition = "2021"
[dependencies]
adb_client = { version = "1.0.1" }
main.rs
use std::net::Ipv4Addr;
use adb_client::{AdbTcpConnection, RustADBError};
fn main() -> Result<(), RustADBError> {
let mut connection = AdbTcpConnection::new(Ipv4Addr::from([127, 0, 0, 1]), 5037)?;
for _ in 0..2 {
let version = connection.version()?;
println!("Android Debug Bridge version {}", version);
}
Ok(())
}
Make this code working
A way making things work with the same code that throw a error is for example to set up a new connection after using the current one. I added one line in your adb "version" implementation but I think it gets round the problem without solving it. But that's perhaps to be expected given the way tcpstream works, I don't know at all.
impl AdbTcpConnection {
/// Gets server's internal version number.
pub fn version(&mut self) -> Result<AdbVersion> {
let version = self.proxy_connection(AdbCommand::Version, true)?;
self.new_connection(); # Added
AdbVersion::try_from(version)
}
}
}