From c166dd5a63d910b7cbd8d2845da838f62298a5f0 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 19 Jan 2021 10:50:23 +1100 Subject: [PATCH] Improve protocol state variant names In the `Executing` state, the future is not always "ready to poll", however it is "executing". --- src/lib.rs | 58 ++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c7f7fdc1..f6af92d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,13 +26,13 @@ type OutboundProtocolFn = enum InboundProtocolState { PendingSubstream(InboundProtocolFn), PendingProtocolFn(InboundSubstream), - ReadyToPoll(Protocol), + Executing(Protocol), } enum OutboundProtocolState { PendingSubstream(OutboundProtocolFn), PendingProtocolFn(OutboundSubstream), - ReadyToPoll(Protocol), + Executing(Protocol), } enum ProtocolState { @@ -149,9 +149,8 @@ where ProtocolState::Inbound(InboundProtocolState::PendingProtocolFn(substream)); } ProtocolState::Inbound(InboundProtocolState::PendingSubstream(protocol_fn)) => { - self.state = ProtocolState::Inbound(InboundProtocolState::ReadyToPoll( - protocol_fn(substream), - )); + self.state = + ProtocolState::Inbound(InboundProtocolState::Executing(protocol_fn(substream))); } ProtocolState::Inbound(_) | ProtocolState::Done => { panic!("Illegal state, substream is already present."); @@ -176,7 +175,7 @@ where ProtocolState::Outbound(OutboundProtocolState::PendingProtocolFn(substream)); } ProtocolState::Outbound(OutboundProtocolState::PendingSubstream(protocol_fn)) => { - self.state = ProtocolState::Outbound(OutboundProtocolState::ReadyToPoll( + self.state = ProtocolState::Outbound(OutboundProtocolState::Executing( protocol_fn(substream), )); } @@ -202,7 +201,7 @@ where ); } ProtocolState::Inbound(InboundProtocolState::PendingProtocolFn(substream)) => { - self.state = ProtocolState::Inbound(InboundProtocolState::ReadyToPoll( + self.state = ProtocolState::Inbound(InboundProtocolState::Executing( protocol_fn(substream), )); } @@ -230,7 +229,7 @@ where ProtocolState::Outbound(OutboundProtocolState::PendingProtocolFn( substream, )) => { - self.state = ProtocolState::Outbound(OutboundProtocolState::ReadyToPoll( + self.state = ProtocolState::Outbound(OutboundProtocolState::Executing( protocol_fn(substream), )); } @@ -276,28 +275,27 @@ where } match mem::replace(&mut self.state, ProtocolState::Poisoned) { - ProtocolState::Inbound(InboundProtocolState::ReadyToPoll(mut protocol)) => { - match protocol.poll_unpin(cx) { - Poll::Ready(Ok(value)) => { - self.state = ProtocolState::Done; - Poll::Ready(ProtocolsHandlerEvent::Custom( - ProtocolOutEvent::InboundFinished(value), - )) - } - Poll::Ready(Err(e)) => { - self.state = ProtocolState::Done; - Poll::Ready(ProtocolsHandlerEvent::Custom( - ProtocolOutEvent::InboundFailed(e), - )) - } - Poll::Pending => { - self.state = - ProtocolState::Inbound(InboundProtocolState::ReadyToPoll(protocol)); - Poll::Pending - } + ProtocolState::Inbound(InboundProtocolState::Executing(mut protocol)) => match protocol + .poll_unpin(cx) + { + Poll::Ready(Ok(value)) => { + self.state = ProtocolState::Done; + Poll::Ready(ProtocolsHandlerEvent::Custom( + ProtocolOutEvent::InboundFinished(value), + )) } - } - ProtocolState::Outbound(OutboundProtocolState::ReadyToPoll(mut protocol)) => { + Poll::Ready(Err(e)) => { + self.state = ProtocolState::Done; + Poll::Ready(ProtocolsHandlerEvent::Custom( + ProtocolOutEvent::InboundFailed(e), + )) + } + Poll::Pending => { + self.state = ProtocolState::Inbound(InboundProtocolState::Executing(protocol)); + Poll::Pending + } + }, + ProtocolState::Outbound(OutboundProtocolState::Executing(mut protocol)) => { match protocol.poll_unpin(cx) { Poll::Ready(Ok(value)) => { self.state = ProtocolState::Done; @@ -313,7 +311,7 @@ where } Poll::Pending => { self.state = - ProtocolState::Outbound(OutboundProtocolState::ReadyToPoll(protocol)); + ProtocolState::Outbound(OutboundProtocolState::Executing(protocol)); Poll::Pending } }