fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
        // Check the client read buffer for new data.
        let socket_closed = self.poll_read()?.is_ready();

        // Look for the presence of a delimiter indicating that
        // a complete message has been sent.
        let pos = self
            .rd
            .windows(1) // A delimiter is one byte
            .enumerate()
            .find(|&(_, bytes)| bytes == MESSAGE_DELIMITER)
            .map(|(i, _)| i);

        if let Some(pos) = pos {
            // Split the message from the read buffer, including
            // the delimiter.
            let mut message = self.rd.split_to(pos + 1);

            // Drop the delimiter from the message.
            message.split_off(pos);

            // Return the message.
            return Ok(Async::Ready(Some(message)));
        }

        // If the socket has closed, stop polling.
        if socket_closed {
            Ok(Async::Ready(None))
        } else {
            Ok(Async::NotReady)
        }
    }
/// Watch for incoming data and return it as messages.
Watch for incoming data and return it as messages.
Watch for incoming data and return it as messages .
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
        // Check the client read buffer for new data.
        let socket_closed = self.poll_read()?.is_ready();
        // Look for the presence of a delimiter indicating that
        // a complete message has been sent.
        let pos = self
            .rd
            .windows(1) // A delimiter is one byte
            .enumerate()
            .find(|&(_, bytes)| bytes == MESSAGE_DELIMITER)
            .map(|(i, _)| i);
        if let Some(pos) = pos {
            // Split the message from the read buffer, including
            // the delimiter.
            let mut message = self.rd.split_to(pos + 1);
            // Drop the delimiter from the message.
            message.split_off(pos);
            // Return the message.
            return Ok(Async::Ready(Some(message)));
        }
        // If the socket has closed, stop polling.
        if socket_closed {
            Ok(Async::Ready(None))
        } else {
            Ok(Async::NotReady)
        }
    }
fn poll ( & mut self ) -> Poll < Option < Self :: Item > , Self :: Error > { // Check the client read buffer for new data. let socket_closed = self . poll_read ( ) ? . is_ready ( ) ; // Look for the presence of a delimiter indicating that // a complete message has been sent. let pos = self . rd . windows ( 1 ) // A delimiter is one byte . enumerate ( ) . find ( | & ( _ , bytes ) | bytes == MESSAGE_DELIMITER ) . map ( | ( i , _ ) | i ) ; if let Some ( pos ) = pos { // Split the message from the read buffer, including // the delimiter. let mut message = self . rd . split_to ( pos + 1 ) ; // Drop the delimiter from the message. message . split_off ( pos ) ; // Return the message. return Ok ( Async :: Ready ( Some ( message ) ) ) ; } // If the socket has closed, stop polling. if socket_closed { Ok ( Async :: Ready ( None ) ) } else { Ok ( Async :: NotReady ) } }
Watch for incoming data and return it as messages.
Watch for incoming data and return it as messages .
&mut self
&mut self