[−][src]Function grin_util::read_write::read_exact
pub fn read_exact(
stream: &mut dyn Read,
buf: &mut [u8],
timeout: Duration,
block_on_empty: bool
) -> Result<()>
The default implementation of read_exact is useless with an async stream (TcpStream) as
it will return as soon as something has been read, regardless of
whether the buffer has been filled (and then errors). This implementation
will block until it has read exactly len
bytes and returns them as a
vec<u8>
. Except for a timeout, this implementation will never return a
partially filled buffer.
The timeout in milliseconds aborts the read when it's met. Note that the
time is not guaranteed to be exact. To support cases where we want to poll
instead of blocking, a block_on_empty
boolean, when false, ensures
read_exact
returns early with a io::ErrorKind::WouldBlock
if nothing
has been read from the socket.