// Uses explicit polling of the write future.
// Returns the payload that could not be written to the socket. If any payload
// is unwritten, caller needs to call this again to send the remaining payload.
Uses explicit polling of the write future.
Returns the payload that could not be written to the socket. If any payload
is unwritten, caller needs to call this again to send the remaining payload.
Uses explicit polling of the write future . Returns the payload that could not be written to the socket . If any payload is unwritten caller needs to call this again to send the remaining payload .
async fn write_using_poll(&mut self, mut payload: Vec<u8>) -> Option<Vec<u8>> {
        let count: Vec<u8> = payload
            .iter()
            .filter(|&v| *v == payload[0])
            .cloned()
            .collect::<Vec<u8>>();
        assert_eq!(count.len(), payload.len());
        let fut = self.writer.write(&payload);
        match poll!(fut) {
            Poll::Ready(result) => match result {
                Ok(sent) => {
                    if sent == payload.len() {
                        println!(
                            "write_poll(): Poll::Ready/complete({}): sent = {}",
                            payload[0], sent,
                        );
                        None
                    } else {
                        println!(
                            "write_poll(): Poll::Ready/partial({}): sent = {}, remaining = {}",
                            payload[0],
                            sent,
                            payload.len() - sent
                        );
                        Some(payload.split_off(sent))
                    }
                }
                Err(e) => {
                    panic!("write_poll(): Write failed: {:?} {}", e, payload[0]);
                }
            },
            Poll::Pending => {
                println!(
                    "write_poll(): Poll::Pending({}): {}",
                    payload[0],
                    payload.len()
                );
                Some(payload)
            }
        }
    }
async fn write_using_poll ( & mut self , mut payload : Vec < u8 > ) -> Option < Vec < u8 > > { let count : Vec < u8 > = payload . iter ( ) . filter ( | & v | * v == payload [ 0 ] ) . cloned ( ) . collect :: < Vec < u8 > > ( ) ; assert_eq ! ( count len ( ) payload len ( ) ) ; let fut = self . writer . write ( & payload ) ; match poll ! ( fut ) { Poll :: Ready ( result ) => match result { Ok ( sent ) => { if sent == payload . len ( ) { println ! ( " " payload [ 0 ] sent ) ; None } else { println ! ( " " payload [ 0 ] sent payload len ( ) sent ) ; Some ( payload . split_off ( sent ) ) } } Err ( e ) => { panic ! ( " " e payload [ 0 ] ) ; } } , Poll :: Pending => { println ! ( " " payload [ 0 ] payload len ( ) ) ; Some ( payload ) } } }
Uses explicit polling of the write future.
Uses explicit polling of the write future .
&mut self
payload
Vec<u8>