fn read<R: BufRead>(stream: &mut R,
                    read_buffer: &mut CryptoBuf,
                    read_len: usize,
                    bytes_read: &mut usize)
                    -> Result<bool, Error> {
    // This loop consumes something or returns, it cannot loop forever.
    loop {
        let consumed_len = match stream.fill_buf() {
            Ok(buf) => {
                if read_buffer.len() + buf.len() < read_len + 4 {

                    read_buffer.extend(buf);
                    buf.len()

                } else {
                    let consumed_len = read_len + 4 - read_buffer.len();
                    read_buffer.extend(&buf[0..consumed_len]);
                    consumed_len
                }
            }
            Err(e) => {
                if e.kind() == std::io::ErrorKind::WouldBlock {
                    return Ok(false);
                } else {
                    return Err(Error::IO(e));
                }
            }
        };
        stream.consume(consumed_len);
        *bytes_read += consumed_len;
        if read_buffer.len() >= 4 + read_len {
            return Ok(true);
        }
    }
}
/// Fills the read buffer, and returns whether a complete message has been read.
///
/// It would be tempting to return either a slice of `stream`, or a
/// slice of `read_buffer`, but except for a very small number of
/// messages, we need double buffering anyway to decrypt in place on
/// `read_buffer`.
Fills the read buffer, and returns whether a complete message has been read.
Fills the read buffer and returns whether a complete message has been read .
fn read<R: BufRead>(stream: &mut R,
                    read_buffer: &mut CryptoBuf,
                    read_len: usize,
                    bytes_read: &mut usize)
                    -> Result<bool, Error> {
    // This loop consumes something or returns, it cannot loop forever.
    loop {
        let consumed_len = match stream.fill_buf() {
            Ok(buf) => {
                if read_buffer.len() + buf.len() < read_len + 4 {
                    read_buffer.extend(buf);
                    buf.len()
                } else {
                    let consumed_len = read_len + 4 - read_buffer.len();
                    read_buffer.extend(&buf[0..consumed_len]);
                    consumed_len
                }
            }
            Err(e) => {
                if e.kind() == std::io::ErrorKind::WouldBlock {
                    return Ok(false);
                } else {
                    return Err(Error::IO(e));
                }
            }
        };
        stream.consume(consumed_len);
        *bytes_read += consumed_len;
        if read_buffer.len() >= 4 + read_len {
            return Ok(true);
        }
    }
}
fn read < R : BufRead > ( stream : & mut R , read_buffer : & mut CryptoBuf , read_len : usize , bytes_read : & mut usize ) -> Result < bool , Error > { // This loop consumes something or returns, it cannot loop forever. loop { let consumed_len = match stream . fill_buf ( ) { Ok ( buf ) => { if read_buffer . len ( ) + buf . len ( ) < read_len + 4 { read_buffer . extend ( buf ) ; buf . len ( ) } else { let consumed_len = read_len + 4 - read_buffer . len ( ) ; read_buffer . extend ( & buf [ 0 .. consumed_len ] ) ; consumed_len } } Err ( e ) => { if e . kind ( ) == std :: io :: ErrorKind :: WouldBlock { return Ok ( false ) ; } else { return Err ( Error :: IO ( e ) ) ; } } } ; stream . consume ( consumed_len ) ; * bytes_read += consumed_len ; if read_buffer . len ( ) >= 4 + read_len { return Ok ( true ) ; } } }
Fills the read buffer, and returns whether a complete message has been read.
Fills the read buffer and returns whether a complete message has been read .
stream
&mut R
read_buffer
&mut CryptoBuf
read_len
usize
bytes_read
&mut usize
stream
&mut R
read_buffer
&mut CryptoBuf
read_len
usize
bytes_read
&mut usize