mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-12 09:31:20 +00:00
Don't allow handlers::poll() to return None (#811)
This commit is contained in:
@ -160,17 +160,17 @@ where
|
||||
fn poll(
|
||||
&mut self,
|
||||
) -> Poll<
|
||||
Option<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>>,
|
||||
ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>,
|
||||
io::Error,
|
||||
> {
|
||||
if !self.send_queue.is_empty() {
|
||||
let message = self.send_queue.remove(0);
|
||||
return Ok(Async::Ready(Some(
|
||||
return Ok(Async::Ready(
|
||||
ProtocolsHandlerEvent::OutboundSubstreamRequest {
|
||||
info: message,
|
||||
upgrade: self.config.clone(),
|
||||
},
|
||||
)));
|
||||
));
|
||||
}
|
||||
|
||||
for n in (0..self.substreams.len()).rev() {
|
||||
@ -181,7 +181,7 @@ where
|
||||
Ok(Async::Ready(Some(message))) => {
|
||||
self.substreams
|
||||
.push(SubstreamState::WaitingInput(substream));
|
||||
return Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(message))));
|
||||
return Ok(Async::Ready(ProtocolsHandlerEvent::Custom(message)));
|
||||
}
|
||||
Ok(Async::Ready(None)) => SubstreamState::Closing(substream),
|
||||
Ok(Async::NotReady) => {
|
||||
@ -217,7 +217,7 @@ where
|
||||
self.substreams.push(SubstreamState::Closing(substream));
|
||||
return Ok(Async::NotReady);
|
||||
}
|
||||
Err(_) => return Ok(Async::Ready(None)),
|
||||
Err(_) => return Ok(Async::Ready(ProtocolsHandlerEvent::Shutdown)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -97,23 +97,21 @@ where
|
||||
fn poll(
|
||||
&mut self,
|
||||
) -> Poll<
|
||||
Option<
|
||||
ProtocolsHandlerEvent<
|
||||
Self::OutboundProtocol,
|
||||
Self::OutboundOpenInfo,
|
||||
Self::OutEvent,
|
||||
>,
|
||||
ProtocolsHandlerEvent<
|
||||
Self::OutboundProtocol,
|
||||
Self::OutboundOpenInfo,
|
||||
Self::OutEvent,
|
||||
>,
|
||||
Self::Error,
|
||||
> {
|
||||
if !self.pending_result.is_empty() {
|
||||
return Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(
|
||||
return Ok(Async::Ready(ProtocolsHandlerEvent::Custom(
|
||||
self.pending_result.remove(0),
|
||||
))));
|
||||
)));
|
||||
}
|
||||
|
||||
if self.shutdown {
|
||||
Ok(Async::Ready(None))
|
||||
Ok(Async::Ready(ProtocolsHandlerEvent::Shutdown))
|
||||
} else {
|
||||
Ok(Async::NotReady)
|
||||
}
|
||||
|
@ -126,24 +126,22 @@ where
|
||||
fn poll(
|
||||
&mut self,
|
||||
) -> Poll<
|
||||
Option<
|
||||
ProtocolsHandlerEvent<
|
||||
Self::OutboundProtocol,
|
||||
Self::OutboundOpenInfo,
|
||||
PeriodicIdHandlerEvent,
|
||||
>,
|
||||
ProtocolsHandlerEvent<
|
||||
Self::OutboundProtocol,
|
||||
Self::OutboundOpenInfo,
|
||||
PeriodicIdHandlerEvent,
|
||||
>,
|
||||
Self::Error,
|
||||
> {
|
||||
if let Some(pending_result) = self.pending_result.take() {
|
||||
return Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(
|
||||
return Ok(Async::Ready(ProtocolsHandlerEvent::Custom(
|
||||
pending_result,
|
||||
))));
|
||||
)));
|
||||
}
|
||||
|
||||
let next_id = match self.next_id {
|
||||
Some(ref mut nid) => nid,
|
||||
None => return Ok(Async::Ready(None)),
|
||||
None => return Ok(Async::Ready(ProtocolsHandlerEvent::Shutdown)),
|
||||
};
|
||||
|
||||
// Poll the future that fires when we need to identify the node again.
|
||||
@ -153,7 +151,7 @@ where
|
||||
next_id.reset(Instant::now() + DELAY_TO_NEXT_ID);
|
||||
let upgrade = self.config.clone();
|
||||
let ev = ProtocolsHandlerEvent::OutboundSubstreamRequest { upgrade, info: () };
|
||||
Ok(Async::Ready(Some(ev)))
|
||||
Ok(Async::Ready(ev))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -497,9 +497,7 @@ where
|
||||
fn poll(
|
||||
&mut self,
|
||||
) -> Poll<
|
||||
Option<
|
||||
ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>,
|
||||
>,
|
||||
ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>,
|
||||
io::Error,
|
||||
> {
|
||||
// Special case if shutting down.
|
||||
@ -512,7 +510,7 @@ where
|
||||
}
|
||||
|
||||
if self.substreams.is_empty() {
|
||||
return Ok(Async::Ready(None));
|
||||
return Ok(Async::Ready(ProtocolsHandlerEvent::Shutdown));
|
||||
} else {
|
||||
return Ok(Async::NotReady);
|
||||
}
|
||||
@ -526,10 +524,10 @@ where
|
||||
match advance_substream(substream, self.config) {
|
||||
(Some(new_state), Some(event), _) => {
|
||||
self.substreams.push(new_state);
|
||||
return Ok(Async::Ready(Some(event)));
|
||||
return Ok(Async::Ready(event));
|
||||
}
|
||||
(None, Some(event), _) => {
|
||||
return Ok(Async::Ready(Some(event)));
|
||||
return Ok(Async::Ready(event));
|
||||
}
|
||||
(Some(new_state), None, false) => {
|
||||
self.substreams.push(new_state);
|
||||
|
@ -214,7 +214,7 @@ where
|
||||
fn poll(
|
||||
&mut self,
|
||||
) -> Poll<
|
||||
Option<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>>,
|
||||
ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>,
|
||||
io::Error,
|
||||
> {
|
||||
// Shortcut for polling a `tokio_timer::Delay`
|
||||
@ -234,7 +234,7 @@ where
|
||||
match mem::replace(&mut self.out_state, OutState::Poisoned) {
|
||||
OutState::Shutdown | OutState::Poisoned => {
|
||||
// This shuts down the whole connection with the remote.
|
||||
Ok(Async::Ready(None))
|
||||
Ok(Async::Ready(ProtocolsHandlerEvent::Shutdown))
|
||||
},
|
||||
|
||||
OutState::Disabled => {
|
||||
@ -246,12 +246,12 @@ where
|
||||
// Note that we ignore the expiration here, as it's pretty unlikely to happen.
|
||||
// The expiration is only here to be transmitted to the `Upgrading`.
|
||||
self.out_state = OutState::Upgrading { expires };
|
||||
Ok(Async::Ready(Some(
|
||||
Ok(Async::Ready(
|
||||
ProtocolsHandlerEvent::OutboundSubstreamRequest {
|
||||
upgrade: self.ping_config,
|
||||
info: (),
|
||||
},
|
||||
)))
|
||||
))
|
||||
}
|
||||
|
||||
// Waiting for the upgrade to be negotiated.
|
||||
@ -263,7 +263,7 @@ where
|
||||
Ready => {
|
||||
self.out_state = OutState::Shutdown;
|
||||
let ev = OutEvent::Unresponsive;
|
||||
Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(ev))))
|
||||
Ok(Async::Ready(ProtocolsHandlerEvent::Custom(ev)))
|
||||
},
|
||||
}),
|
||||
|
||||
@ -278,12 +278,12 @@ where
|
||||
next_ping: Delay::new(Instant::now() + self.delay_to_next_ping),
|
||||
};
|
||||
let ev = OutEvent::PingSuccess(started.elapsed());
|
||||
return Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(ev))));
|
||||
return Ok(Async::Ready(ProtocolsHandlerEvent::Custom(ev)));
|
||||
}
|
||||
Async::NotReady => {}
|
||||
Async::Ready(None) => {
|
||||
self.out_state = OutState::Shutdown;
|
||||
return Ok(Async::Ready(None));
|
||||
return Ok(Async::Ready(ProtocolsHandlerEvent::Shutdown));
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,7 +298,7 @@ where
|
||||
Ready => {
|
||||
self.out_state = OutState::Shutdown;
|
||||
let ev = OutEvent::Unresponsive;
|
||||
Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(ev))))
|
||||
Ok(Async::Ready(ProtocolsHandlerEvent::Custom(ev)))
|
||||
},
|
||||
})
|
||||
}
|
||||
@ -314,7 +314,7 @@ where
|
||||
let expires = Delay::new(Instant::now() + self.ping_timeout);
|
||||
substream.ping(Instant::now());
|
||||
self.out_state = OutState::WaitingForPong { substream, expires };
|
||||
Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(OutEvent::PingStart))))
|
||||
Ok(Async::Ready(ProtocolsHandlerEvent::Custom(OutEvent::PingStart)))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ where
|
||||
fn poll(
|
||||
&mut self,
|
||||
) -> Poll<
|
||||
Option<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>>,
|
||||
ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>,
|
||||
Self::Error,
|
||||
> {
|
||||
// Removes each substream one by one, and pushes them back if they're not ready (which
|
||||
@ -133,7 +133,7 @@ where
|
||||
|
||||
// Special case if shutting down.
|
||||
if self.shutdown && self.ping_in_substreams.is_empty() {
|
||||
return Ok(Async::Ready(None));
|
||||
return Ok(Async::Ready(ProtocolsHandlerEvent::Shutdown));
|
||||
}
|
||||
|
||||
Ok(Async::NotReady)
|
||||
|
Reference in New Issue
Block a user