rpc/client: minor cleanup

This commit is contained in:
aggstam
2022-12-10 02:27:55 +02:00
parent 6828d720f4
commit e99b8dc5a3

View File

@@ -262,12 +262,10 @@ impl RpcClient {
// If data is incomplete, this will fail, therefore,
// we re-execute read and write after previous read in the buffer,
// and repeat until the data in buffer can be converted.
let mut total = 0;
let mut n = 0;
loop {
n = timeout(read_timeout, async { stream.read(&mut buf[n..]).await }).await?;
total += n;
match serde_json::from_slice(&buf[0..total]) {
n += timeout(read_timeout, async { stream.read(&mut buf[n..]).await }).await?;
match serde_json::from_slice(&buf[0..n]) {
Ok(reply) => {
result_send.send(reply).await?;
break