fn read_local_stream_port(stream: &mut UnixStream) -> Result<u32> {
        let mut buf = [0u8; 32];

        // This is the minimum number of bytes that we should be able to read, when parsing a
        // valid connection request. I.e. `b"connect 0\n".len()`.
        const MIN_READ_LEN: usize = 10;

        // Bring in the minimum number of bytes that we should be able to read.
        stream
            .read_exact(&mut buf[..MIN_READ_LEN])
            .map_err(Error::UnixRead)?;

        // Now, finish reading the destination port number, by bringing in one byte at a time,
        // until we reach an EOL terminator (or our buffer space runs out).  Yeah, not
        // particularly proud of this approach, but it will have to do for now.
        let mut blen = MIN_READ_LEN;
        while buf[blen - 1] != b'\n' && blen < buf.len() {
            stream
                .read_exact(&mut buf[blen..=blen])
                .map_err(Error::UnixRead)?;
            blen += 1;
        }

        let mut word_iter = std::str::from_utf8(&buf[..blen])
            .map_err(|_| Error::InvalidPortRequest)?
            .split_whitespace();

        word_iter
            .next()
            .ok_or(Error::InvalidPortRequest)
            .and_then(|word| {
                if word.to_lowercase() == "connect" {
                    Ok(())
                } else {
                    Err(Error::InvalidPortRequest)
                }
            })
            .and_then(|_| word_iter.next().ok_or(Error::InvalidPortRequest))
            .and_then(|word| word.parse::<u32>().map_err(|_| Error::InvalidPortRequest))
            .map_err(|_| Error::InvalidPortRequest)
    }
/// Parse a host "connect" command, and extract the destination vsock port.
Parse a host "connect" command, and extract the destination vsock port.
Parse a host " connect " command and extract the destination vsock port .
fn read_local_stream_port(stream: &mut UnixStream) -> Result<u32> {
        let mut buf = [0u8; 32];
        // This is the minimum number of bytes that we should be able to read, when parsing a
        // valid connection request. I.e. `b"connect 0\n".len()`.
        const MIN_READ_LEN: usize = 10;
        // Bring in the minimum number of bytes that we should be able to read.
        stream
            .read_exact(&mut buf[..MIN_READ_LEN])
            .map_err(Error::UnixRead)?;
        // Now, finish reading the destination port number, by bringing in one byte at a time,
        // until we reach an EOL terminator (or our buffer space runs out).  Yeah, not
        // particularly proud of this approach, but it will have to do for now.
        let mut blen = MIN_READ_LEN;
        while buf[blen - 1] != b'\n' && blen < buf.len() {
            stream
                .read_exact(&mut buf[blen..=blen])
                .map_err(Error::UnixRead)?;
            blen += 1;
        }
        let mut word_iter = std::str::from_utf8(&buf[..blen])
            .map_err(|_| Error::InvalidPortRequest)?
            .split_whitespace();
        word_iter
            .next()
            .ok_or(Error::InvalidPortRequest)
            .and_then(|word| {
                if word.to_lowercase() == "connect" {
                    Ok(())
                } else {
                    Err(Error::InvalidPortRequest)
                }
            })
            .and_then(|_| word_iter.next().ok_or(Error::InvalidPortRequest))
            .and_then(|word| word.parse::<u32>().map_err(|_| Error::InvalidPortRequest))
            .map_err(|_| Error::InvalidPortRequest)
    }
fn read_local_stream_port ( stream : & mut UnixStream ) -> Result < u32 > { let mut buf = [ 0u8 ; 32 ] ; // This is the minimum number of bytes that we should be able to read, when parsing a // valid connection request. I.e. `b"connect 0\n".len()`. const MIN_READ_LEN : usize = 10 ; // Bring in the minimum number of bytes that we should be able to read. stream . read_exact ( & mut buf [ .. MIN_READ_LEN ] ) . map_err ( Error :: UnixRead ) ? ; // Now, finish reading the destination port number, by bringing in one byte at a time, // until we reach an EOL terminator (or our buffer space runs out).  Yeah, not // particularly proud of this approach, but it will have to do for now. let mut blen = MIN_READ_LEN ; while buf [ blen - 1 ] != b'\n' && blen < buf . len ( ) { stream . read_exact ( & mut buf [ blen ..= blen ] ) . map_err ( Error :: UnixRead ) ? ; blen += 1 ; } let mut word_iter = std :: str :: from_utf8 ( & buf [ .. blen ] ) . map_err ( | _ | Error :: InvalidPortRequest ) ? . split_whitespace ( ) ; word_iter . next ( ) . ok_or ( Error :: InvalidPortRequest ) . and_then ( | word | { if word . to_lowercase ( ) == " " { Ok ( ( ) ) } else { Err ( Error :: InvalidPortRequest ) } } ) . and_then ( | _ | word_iter . next ( ) . ok_or ( Error :: InvalidPortRequest ) ) . and_then ( | word | word . parse :: < u32 > ( ) . map_err ( | _ | Error :: InvalidPortRequest ) ) . map_err ( | _ | Error :: InvalidPortRequest ) }
Parse a host "connect" command, and extract the destination vsock port.
Parse a host " connect " command and extract the destination vsock port .
stream
&mut UnixStream
stream
&mut UnixStream