/// Send a given request and wait for response.
Send a given request and wait for response.
Send a given request and wait for response .
fn perform_request(&mut self, request: &Request) -> Result<Response> {
        let request = format!("{}", request)
            .into_bytes();
        try!(self.stream.write_all(&request));
        // process buffered data
        while self.offset < self.buffer.len() && !self.parser.is_complete() {
            let data = &self.buffer[self.offset..];
            self.offset += try!(self.parser.add(data));
        }
        // reset the buffer if it's empty
        if self.offset >= self.buffer.len() {
            self.buffer.clear();
            self.offset = 0;
        }
        let mut buffer = [0u8; 4096];
        while !self.parser.is_complete() {
            let length = try!(self.stream.read(&mut buffer));
            if length == 0 {
                break;
            }
            let mut offset = 0;
            while offset < length && !self.parser.is_complete() {
                offset += try!(self.parser.add(&buffer[offset..length]));
            }
            // put all possible leftovers into the internal buffer
            if offset < length {
                self.buffer.extend_from_slice(&buffer[offset..length]);
            }
        }
        let response = try!(self.parser.response());
        self.parser.clear();
        Ok(response)
    }
fn perform_request ( & mut self , request : & Request ) -> Result < Response > { let request = format ! ( " " request ) . into_bytes ( ) ; try ! ( self stream write_all ( request ) ) ; // process buffered data while self . offset < self . buffer . len ( ) && ! self . parser . is_complete ( ) { let data = & self . buffer [ self . offset .. ] ; self . offset += try ! ( self parser add ( data ) ) ; } // reset the buffer if it's empty if self . offset >= self . buffer . len ( ) { self . buffer . clear ( ) ; self . offset = 0 ; } let mut buffer = [ 0u8 ; 4096 ] ; while ! self . parser . is_complete ( ) { let length = try ! ( self stream read ( mut buffer ) ) ; if length == 0 { break ; } let mut offset = 0 ; while offset < length && ! self . parser . is_complete ( ) { offset += try ! ( self parser add ( buffer [ offset length ] ) ) ; } // put all possible leftovers into the internal buffer if offset < length { self . buffer . extend_from_slice ( & buffer [ offset .. length ] ) ; } } let response = try ! ( self parser response ( ) ) ; self . parser . clear ( ) ; Ok ( response ) }
Send a given request and wait for response.
Send a given request and wait for response .
&mut self
request
&Request