mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-12 09:31:20 +00:00
core/muxing: Replace Into<io::Error>
bound on StreamMuxer
with std::error::Error
(#2710)
* core/muxing: Remove `Into<io::Error>` bound from `StreamMuxer::Error` This allows us to preserve the type information of a muxer's concrete error as long as possible. For `StreamMuxerBox`, we leverage `io::Error`'s capability of wrapping any error that implements `Into<Box<dyn Error>>`. * Use `?` in `Connection::poll` * Use `?` in `muxing::boxed::Wrap` * Use `futures::ready!` in `muxing::boxed::Wrap` * Fill PR number into changelog * Put `Error + Send + Sync` bounds directly on `StreamMuxer::Error` * Move `Send + Sync` bounds to higher layers * Use `map_inbound_stream` helper * Update changelog to match new implementation
This commit is contained in:
@ -137,40 +137,38 @@ where
|
||||
) -> Poll<Result<Event<THandler::OutEvent>, ConnectionError<THandler::Error>>> {
|
||||
loop {
|
||||
// Poll the handler for new events.
|
||||
match self.handler.poll(cx) {
|
||||
match self.handler.poll(cx)? {
|
||||
Poll::Pending => {}
|
||||
Poll::Ready(Ok(handler_wrapper::Event::OutboundSubstreamRequest(user_data))) => {
|
||||
Poll::Ready(handler_wrapper::Event::OutboundSubstreamRequest(user_data)) => {
|
||||
self.muxing.open_substream(user_data);
|
||||
continue;
|
||||
}
|
||||
Poll::Ready(Ok(handler_wrapper::Event::Custom(event))) => {
|
||||
Poll::Ready(handler_wrapper::Event::Custom(event)) => {
|
||||
return Poll::Ready(Ok(Event::Handler(event)));
|
||||
}
|
||||
Poll::Ready(Err(err)) => return Poll::Ready(Err(err.into())),
|
||||
}
|
||||
|
||||
// Perform I/O on the connection through the muxer, informing the handler
|
||||
// of new substreams.
|
||||
match self.muxing.poll(cx) {
|
||||
match self.muxing.poll(cx)? {
|
||||
Poll::Pending => {}
|
||||
Poll::Ready(Ok(SubstreamEvent::InboundSubstream { substream })) => {
|
||||
Poll::Ready(SubstreamEvent::InboundSubstream { substream }) => {
|
||||
self.handler
|
||||
.inject_substream(substream, SubstreamEndpoint::Listener);
|
||||
continue;
|
||||
}
|
||||
Poll::Ready(Ok(SubstreamEvent::OutboundSubstream {
|
||||
Poll::Ready(SubstreamEvent::OutboundSubstream {
|
||||
user_data,
|
||||
substream,
|
||||
})) => {
|
||||
}) => {
|
||||
let endpoint = SubstreamEndpoint::Dialer(user_data);
|
||||
self.handler.inject_substream(substream, endpoint);
|
||||
continue;
|
||||
}
|
||||
Poll::Ready(Ok(SubstreamEvent::AddressChange(address))) => {
|
||||
Poll::Ready(SubstreamEvent::AddressChange(address)) => {
|
||||
self.handler.inject_address_change(&address);
|
||||
return Poll::Ready(Ok(Event::AddressChange(address)));
|
||||
}
|
||||
Poll::Ready(Err(err)) => return Poll::Ready(Err(ConnectionError::IO(err))),
|
||||
}
|
||||
|
||||
return Poll::Pending;
|
||||
|
Reference in New Issue
Block a user