From 921be53ef0fe11902dcc9c8ff732faaf9017ff02 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 5 Aug 2021 07:45:33 +0700 Subject: [PATCH] Allow retries during read in deserlisation --- crates/core/src/bc/de.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/crates/core/src/bc/de.rs b/crates/core/src/bc/de.rs index f61db6e..32de4cf 100644 --- a/crates/core/src/bc/de.rs +++ b/crates/core/src/bc/de.rs @@ -48,15 +48,28 @@ where Err(e) => return Err(e.into()), }; - if 0 == (&mut rdr) - .take(to_read.get() as u64) - .read_to_end(&mut input)? - { - return Err(std::io::Error::new( - std::io::ErrorKind::UnexpectedEof, - "Read returned 0 bytes", - ) - .into()); + loop { + match (&mut rdr) + .take(to_read.get() as u64) + .read_to_end(&mut input) + { + Ok(0) => { + return Err(std::io::Error::new( + std::io::ErrorKind::UnexpectedEof, + "Read returned 0 bytes", + ) + .into()); + } + Ok(_) => break, + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { + // This is a temporaily unavaliable resource + // We should just wait and try again + } + Err(e) => { + log::error!("HERE {:?}", e); + return Err(e.into()); + } + } } } }