From a5e5600e68e3d3eb3bc697faa793c5a9701b49c9 Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Sat, 17 Jun 2023 11:13:04 +0100 Subject: [PATCH] poll_ready: try to flush when !ready --- src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 65eafac9..71f9017e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -326,11 +326,15 @@ where { type Error = WsError; - fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { if self.ready { Poll::Ready(Ok(())) } else { - Poll::Pending + // Currently blocked so try to flush the blockage away + (*self).with_context(Some((ContextWaker::Write, cx)), |s| cvt(s.flush())).map(|r| { + self.ready = true; + r + }) } } @@ -355,10 +359,10 @@ where } fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - self.ready = true; (*self).with_context(Some((ContextWaker::Write, cx)), |s| cvt(s.flush())).map(|r| { - // WebSocket connection has just been closed. Flushing completed, not an error. + self.ready = true; match r { + // WebSocket connection has just been closed. Flushing completed, not an error. Err(WsError::ConnectionClosed) => Ok(()), other => other, }