[pbs-devel] [PATCH proxmox 3/9] proxmox/tools/websocket: use ready macro for WebSocketWriter

Dominik Csapak d.csapak at proxmox.com
Tue Jul 14 13:09:51 CEST 2020


Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 proxmox/src/tools/websocket.rs | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/proxmox/src/tools/websocket.rs b/proxmox/src/tools/websocket.rs
index 04173bb..c30293f 100644
--- a/proxmox/src/tools/websocket.rs
+++ b/proxmox/src/tools/websocket.rs
@@ -222,16 +222,19 @@ impl<W: AsyncWrite + Unpin> AsyncWrite for WebSocketWriter<W> {
         // we have a frame in any case, so unwrap is ok
         let (buf, pos, origsize) = this.frame.as_mut().unwrap();
         loop {
-            match Pin::new(&mut this.writer).poll_write(cx, &buf[*pos..]) {
-                Poll::Ready(Ok(size)) => {
+            match ready!(Pin::new(&mut this.writer).poll_write(cx, &buf[*pos..])) {
+                Ok(size) => {
                     *pos += size;
                     if *pos == buf.len() {
                         let size = *origsize;
                         this.frame = None;
                         return Poll::Ready(Ok(size));
                     }
-                }
-                other => return other,
+                },
+                Err(err) => {
+                    eprintln!("error in writer: {}", err);
+                    return Poll::Ready(Err(Error::new(ErrorKind::Other, err)))
+                },
             }
         }
     }
-- 
2.20.1






More information about the pbs-devel mailing list