Continue reading session data in the same iteration if available
This commit is contained in:
parent
925869d462
commit
8c7bcdafdb
@ -436,7 +436,7 @@ impl EncryptedConnection {
|
|||||||
|
|
||||||
/// Readable IO handler. Tracker receive status and returns decoded packet if avaialable.
|
/// Readable IO handler. Tracker receive status and returns decoded packet if avaialable.
|
||||||
pub fn readable<Message>(&mut self, io: &IoContext<Message>) -> Result<Option<Packet>, UtilError> where Message: Send + Clone{
|
pub fn readable<Message>(&mut self, io: &IoContext<Message>) -> Result<Option<Packet>, UtilError> where Message: Send + Clone{
|
||||||
io.clear_timer(self.connection.token).unwrap();
|
try!(io.clear_timer(self.connection.token));
|
||||||
if let EncryptedConnectionState::Header = self.read_state {
|
if let EncryptedConnectionState::Header = self.read_state {
|
||||||
if let Some(data) = try!(self.connection.readable()) {
|
if let Some(data) = try!(self.connection.readable()) {
|
||||||
try!(self.read_header(&data));
|
try!(self.read_header(&data));
|
||||||
|
@ -683,6 +683,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
|
|||||||
Some(_) => packet_data.push((protocol, packet_id, data)),
|
Some(_) => packet_data.push((protocol, packet_id, data)),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Ok(SessionData::Continue) => (),
|
||||||
Ok(SessionData::None) => break,
|
Ok(SessionData::None) => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,8 @@ pub enum SessionData {
|
|||||||
/// Zero based packet ID
|
/// Zero based packet ID
|
||||||
packet_id: u8,
|
packet_id: u8,
|
||||||
},
|
},
|
||||||
|
/// Session has more data to be read
|
||||||
|
Continue,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shared session information
|
/// Shared session information
|
||||||
@ -329,16 +331,19 @@ impl Session {
|
|||||||
PACKET_DISCONNECT => {
|
PACKET_DISCONNECT => {
|
||||||
let rlp = UntrustedRlp::new(&packet.data[1..]);
|
let rlp = UntrustedRlp::new(&packet.data[1..]);
|
||||||
let reason: u8 = try!(rlp.val_at(0));
|
let reason: u8 = try!(rlp.val_at(0));
|
||||||
|
if self.had_hello {
|
||||||
|
debug!("Disconnected: {}: {:?}", self.token(), DisconnectReason::from_u8(reason));
|
||||||
|
}
|
||||||
Err(From::from(NetworkError::Disconnect(DisconnectReason::from_u8(reason))))
|
Err(From::from(NetworkError::Disconnect(DisconnectReason::from_u8(reason))))
|
||||||
}
|
}
|
||||||
PACKET_PING => {
|
PACKET_PING => {
|
||||||
try!(self.send_pong(io));
|
try!(self.send_pong(io));
|
||||||
Ok(SessionData::None)
|
Ok(SessionData::Continue)
|
||||||
},
|
},
|
||||||
PACKET_PONG => {
|
PACKET_PONG => {
|
||||||
self.pong_time_ns = Some(time::precise_time_ns());
|
self.pong_time_ns = Some(time::precise_time_ns());
|
||||||
self.info.ping_ms = Some((self.pong_time_ns.unwrap() - self.ping_time_ns) / 1000_000);
|
self.info.ping_ms = Some((self.pong_time_ns.unwrap() - self.ping_time_ns) / 1000_000);
|
||||||
Ok(SessionData::None)
|
Ok(SessionData::Continue)
|
||||||
},
|
},
|
||||||
PACKET_GET_PEERS => Ok(SessionData::None), //TODO;
|
PACKET_GET_PEERS => Ok(SessionData::None), //TODO;
|
||||||
PACKET_PEERS => Ok(SessionData::None),
|
PACKET_PEERS => Ok(SessionData::None),
|
||||||
@ -348,7 +353,7 @@ impl Session {
|
|||||||
i += 1;
|
i += 1;
|
||||||
if i == self.info.capabilities.len() {
|
if i == self.info.capabilities.len() {
|
||||||
debug!(target: "network", "Unknown packet: {:?}", packet_id);
|
debug!(target: "network", "Unknown packet: {:?}", packet_id);
|
||||||
return Ok(SessionData::None)
|
return Ok(SessionData::Continue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +364,7 @@ impl Session {
|
|||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
debug!(target: "network", "Unknown packet: {:?}", packet_id);
|
debug!(target: "network", "Unknown packet: {:?}", packet_id);
|
||||||
Ok(SessionData::None)
|
Ok(SessionData::Continue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user