sc-network: Return on Poll::Pending. (#5295)

If polling encounters a `Poll::Pending` we need to return it instead of
continuing the loop which may turn it into a blocking operation, causing
problems with executors.
This commit is contained in:
Toralf Wittner authored and GitHub committed 2020-03-18 11:21:10 +00:00
1 parent 733d486814
commit 89b93d9d4b
1 file changed
+8 -4
@@ -200,15 +200,19 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin,
Err(err) => return Poll::Ready(Some(Err(err))),
}
},
Poll::Pending =>
*this.handshake = NotificationsInSubstreamHandshake::PendingSend(msg),
Poll::Pending => {
*this.handshake = NotificationsInSubstreamHandshake::PendingSend(msg);
return Poll::Pending
}
},
NotificationsInSubstreamHandshake::Close =>
match Sink::poll_close(this.socket.as_mut(), cx)? {
Poll::Ready(()) =>
*this.handshake = NotificationsInSubstreamHandshake::Sent,
Poll::Pending =>
*this.handshake = NotificationsInSubstreamHandshake::Close,
Poll::Pending => {
*this.handshake = NotificationsInSubstreamHandshake::Close;
return Poll::Pending
}
},
}
}