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

                        self.read.buffer.extend(buf);
                        buf.len()

                    } else {
                        let consumed_len = self.read.len + 4 - self.read.buffer.len();
                        self.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);
            self.read.bytes += consumed_len;
            if self.read.buffer.len() >= 4 + self.read.len {
                self.read.len = 0;
                self.read.seqn += 1;
                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>(&mut self, stream: &mut R) -> Result<bool, Error> {
        // This loop consumes something or returns, it cannot loop forever.
        loop {
            let consumed_len = match stream.fill_buf() {
                Ok(buf) => {
                    if self.read.buffer.len() + buf.len() < self.read.len + 4 {
                        self.read.buffer.extend(buf);
                        buf.len()
                    } else {
                        let consumed_len = self.read.len + 4 - self.read.buffer.len();
                        self.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);
            self.read.bytes += consumed_len;
            if self.read.buffer.len() >= 4 + self.read.len {
                self.read.len = 0;
                self.read.seqn += 1;
                return Ok(true);
            }
        }
    }
fn read < R : BufRead > ( & mut self , stream : & mut R ) -> Result < bool , Error > { // This loop consumes something or returns, it cannot loop forever. loop { let consumed_len = match stream . fill_buf ( ) { Ok ( buf ) => { if self . read . buffer . len ( ) + buf . len ( ) < self . read . len + 4 { self . read . buffer . extend ( buf ) ; buf . len ( ) } else { let consumed_len = self . read . len + 4 - self . read . buffer . len ( ) ; self . 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 ) ; self . read . bytes += consumed_len ; if self . read . buffer . len ( ) >= 4 + self . read . len { self . read . len = 0 ; self . read . seqn += 1 ; 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 .
&mut self
stream
&mut R
&mut self
stream
&mut R