Don't set KeepAlive to Until all the time (#1398)

* Don't set KeepAlive to Until all the time

* Address concerns
This commit is contained in:
Pierre Krieger 2020-01-20 13:55:25 +01:00 committed by GitHub
parent c241014ddb
commit 0ed684ee30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -403,7 +403,7 @@ where
allow_listening, allow_listening,
next_connec_unique_id: UniqueConnecId(0), next_connec_unique_id: UniqueConnecId(0),
substreams: Vec::new(), substreams: Vec::new(),
keep_alive: KeepAlive::Yes, keep_alive: KeepAlive::Until(Instant::now() + Duration::from_secs(10)),
} }
} }
@ -645,6 +645,10 @@ where
) -> Poll< ) -> Poll<
ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent, Self::Error>, ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent, Self::Error>,
> { > {
if self.substreams.is_empty() {
return Poll::Pending;
}
// We remove each element from `substreams` one by one and add them back. // We remove each element from `substreams` one by one and add them back.
for n in (0..self.substreams.len()).rev() { for n in (0..self.substreams.len()).rev() {
let mut substream = self.substreams.swap_remove(n); let mut substream = self.substreams.swap_remove(n);
@ -656,6 +660,9 @@ where
return Poll::Ready(event); return Poll::Ready(event);
} }
(None, Some(event), _) => { (None, Some(event), _) => {
if self.substreams.is_empty() {
self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10));
}
return Poll::Ready(event); return Poll::Ready(event);
} }
(Some(new_state), None, false) => { (Some(new_state), None, false) => {
@ -674,6 +681,7 @@ where
} }
if self.substreams.is_empty() { if self.substreams.is_empty() {
// We destroyed all substreams in this function.
self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10)); self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10));
} else { } else {
self.keep_alive = KeepAlive::Yes; self.keep_alive = KeepAlive::Yes;