nervosnetwork / tentacle

A multiplexed p2p network framework that supports custom protocols

Home Page:https://docs.rs/tentacle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle the collection errors both reading and writing

yangby-cryptape opened this issue · comments

Handle the collection errors when reading data:

Poll::Ready(Some(Err(err))) => {
debug!("sub stream codec error: {:?}", err);
match err.kind() {
ErrorKind::BrokenPipe
| ErrorKind::ConnectionAborted
| ErrorKind::ConnectionReset
| ErrorKind::NotConnected
| ErrorKind::UnexpectedEof => self.dead = true,
_ => {
self.error_close(cx, err);
}
}
Poll::Ready(None)
}

But not when writing:

if let Err(err) = self.send_data(cx) {
// Whether it is a read send error or a flush error,
// the most essential problem is that there is a problem with the external network.
// Close the protocol stream directly.
debug!(
"protocol [{}] close because of extern network",
self.proto_id
);
self.output_event(
cx,
ProtocolEvent::Error {
id: self.id,
proto_id: self.proto_id,
error: err,
},
);
self.dead = true;
}