From c475e71c167e1725d50d654330ecf18852afa38c Mon Sep 17 00:00:00 2001 From: AIkorsky Date: Thu, 25 Mar 2021 15:54:35 +0300 Subject: [PATCH] Always register for readiness events in ConnectingInstance::poll --- tokio/src/net/windows/named_pipe.rs | 52 +++++++++++++++-------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/tokio/src/net/windows/named_pipe.rs b/tokio/src/net/windows/named_pipe.rs index 90b62b3a8c5..b505c42773c 100644 --- a/tokio/src/net/windows/named_pipe.rs +++ b/tokio/src/net/windows/named_pipe.rs @@ -48,32 +48,34 @@ impl Future for ConnectingInstance { type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match mem::replace(&mut *self, ConnectingInstance::Ready(None)) { - Self::Ready(None) => { - // poll on completed future - Poll::Pending - } - Self::Ready(Some(pipe)) => Poll::Ready(Ok(pipe)), - Self::Connecting(pipe) => match pipe.poll_write_ready(cx) { - Poll::Ready(Ok(_)) => Poll::Ready(Ok(pipe)), - Poll::Ready(Err(err)) => Poll::Ready(Err(err)), - Poll::Pending => { - *self = Self::Connecting(pipe); - Poll::Pending - } - }, - Self::New(pipe) => match pipe.io_ref().connect() { - Ok(()) => { - *self = Self::Connecting(pipe); - Poll::Pending - } - Err(err) if err.kind() == ErrorKind::WouldBlock => { - *self = Self::Connecting(pipe); - Poll::Pending + loop { + match mem::replace(&mut *self, ConnectingInstance::Ready(None)) { + Self::Ready(None) => { + // poll on completed future + break Poll::Pending; } - Err(err) => Poll::Ready(Err(err)), - }, - Self::Error(err) => Poll::Ready(Err(err)), + Self::Ready(Some(pipe)) => break Poll::Ready(Ok(pipe)), + Self::Connecting(pipe) => match pipe.poll_write_ready(cx) { + Poll::Ready(Ok(_)) => break Poll::Ready(Ok(pipe)), + Poll::Ready(Err(err)) => break Poll::Ready(Err(err)), + Poll::Pending => { + *self = Self::Connecting(pipe); + break Poll::Pending; + } + }, + Self::New(pipe) => match pipe.io_ref().connect() { + Ok(()) => { + *self = Self::Connecting(pipe); + // loop again to poll for write readiness + } + Err(err) if err.kind() == ErrorKind::WouldBlock => { + *self = Self::Connecting(pipe); + // loop again to poll for write readiness + } + Err(err) => break Poll::Ready(Err(err)), + }, + Self::Error(err) => break Poll::Ready(Err(err)), + } } } }