fn read(&mut self, token: Token) {
        if let Ok(response) = self.connections[token].read() {
            if !response.is_empty() {
                let t0 = self.times[token.0];
                let t1 = self.rtimes[token.0];

                let parsed = self.protocol.parse(&response);

                let status = match parsed {
                    ParsedResponse::Ok => Stat::ResponseOk,
                    ParsedResponse::Hit => {
                        let _ = self.stats.send(Sample::new(t0, t1, Stat::ResponseOk));
                        Stat::ResponseOkHit
                    }
                    ParsedResponse::Miss => {
                        let _ = self.stats.send(Sample::new(t0, t1, Stat::ResponseOk));
                        Stat::ResponseOkMiss
                    }
                    _ => Stat::ResponseError,
                };

                if parsed != ParsedResponse::Incomplete {
                    let _ = self.stats.send(Sample::new(t0, t1, status.clone()));
                    trace!("switch to established");
                    self.clear_timer(token);
                    self.set_state(token, State::Established);
                    self.idle(token);
                    self.connections[token].clear_failures();
                }
            }
        } else {
            debug!("read error. reconnect");
            self.send_stat(token, Stat::ConnectError);
            self.reconnect(token);
        }
    }
/// read and parse response
/// - reconnect on failure
/// - transition to Writing when response is complete
read and parse response
reconnect on failure
transition to Writing when response is complete
read and parse response reconnect on failure transition to Writing when response is complete
fn read(&mut self, token: Token) {
        if let Ok(response) = self.connections[token].read() {
            if !response.is_empty() {
                let t0 = self.times[token.0];
                let t1 = self.rtimes[token.0];
                let parsed = self.protocol.parse(&response);
                let status = match parsed {
                    ParsedResponse::Ok => Stat::ResponseOk,
                    ParsedResponse::Hit => {
                        let _ = self.stats.send(Sample::new(t0, t1, Stat::ResponseOk));
                        Stat::ResponseOkHit
                    }
                    ParsedResponse::Miss => {
                        let _ = self.stats.send(Sample::new(t0, t1, Stat::ResponseOk));
                        Stat::ResponseOkMiss
                    }
                    _ => Stat::ResponseError,
                };
                if parsed != ParsedResponse::Incomplete {
                    let _ = self.stats.send(Sample::new(t0, t1, status.clone()));
                    trace!("switch to established");
                    self.clear_timer(token);
                    self.set_state(token, State::Established);
                    self.idle(token);
                    self.connections[token].clear_failures();
                }
            }
        } else {
            debug!("read error. reconnect");
            self.send_stat(token, Stat::ConnectError);
            self.reconnect(token);
        }
    }
fn read ( & mut self , token : Token ) { if let Ok ( response ) = self . connections [ token ] . read ( ) { if ! response . is_empty ( ) { let t0 = self . times [ token . 0 ] ; let t1 = self . rtimes [ token . 0 ] ; let parsed = self . protocol . parse ( & response ) ; let status = match parsed { ParsedResponse :: Ok => Stat :: ResponseOk , ParsedResponse :: Hit => { let _ = self . stats . send ( Sample :: new ( t0 , t1 , Stat :: ResponseOk ) ) ; Stat :: ResponseOkHit } ParsedResponse :: Miss => { let _ = self . stats . send ( Sample :: new ( t0 , t1 , Stat :: ResponseOk ) ) ; Stat :: ResponseOkMiss } _ => Stat :: ResponseError , } ; if parsed != ParsedResponse :: Incomplete { let _ = self . stats . send ( Sample :: new ( t0 , t1 , status . clone ( ) ) ) ; trace ! ( " " ) ; self . clear_timer ( token ) ; self . set_state ( token , State :: Established ) ; self . idle ( token ) ; self . connections [ token ] . clear_failures ( ) ; } } } else { debug ! ( " " ) ; self . send_stat ( token , Stat :: ConnectError ) ; self . reconnect ( token ) ; } }
read and parse response
 reconnect on failure
 transition to Writing when response is complete
read and parse response reconnect on failure transition to Writing when response is complete
&mut self
token
Token
&mut self
token
Token