From ca7333cb92fba65a8280d0faba5fea4dbc9b2051 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 14 Jul 2020 13:09:52 +0200 Subject: [PATCH] proxmox/tools/websocket: correctly return eof only return Ok(0) when the upstream reader did return that, not when we have no data in the buffer, else the downstream reader believes we are EOF (even if we are not) Signed-off-by: Dominik Csapak Signed-off-by: Wolfgang Bumiller --- proxmox/src/tools/websocket.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/proxmox/src/tools/websocket.rs b/proxmox/src/tools/websocket.rs index c30293f5..d59b7ad6 100644 --- a/proxmox/src/tools/websocket.rs +++ b/proxmox/src/tools/websocket.rs @@ -432,7 +432,7 @@ impl WebSocketReader { enum ReaderState { NoData, - WaitingForData(Pin> + Send + 'static>>), + WaitingForData(Pin> + Send + 'static>>), HaveData, } @@ -463,18 +463,20 @@ impl AsyncRead for WebSocketReader let future = async move { buffer.read_from_async(&mut reader) .await - .map(move |_| (reader, buffer)) + .map(move |len| (len, reader, buffer)) }; this.state = ReaderState::WaitingForData(future.boxed()); }, ReaderState::WaitingForData(ref mut future) => { match ready!(future.as_mut().poll(cx)) { - Ok((reader, buffer)) => { + Ok((len, reader, buffer)) => { this.reader = Some(reader); this.read_buffer = Some(buffer); this.state = ReaderState::HaveData; - + if len == 0 { + return Poll::Ready(Ok(0)); + } }, Err(err) => return Poll::Ready(Err(Error::new(ErrorKind::Other, err))), } @@ -545,7 +547,9 @@ impl AsyncRead for WebSocketReader }; this.read_buffer = Some(read_buffer); - return Poll::Ready(Ok(offset)); + if offset > 0 { + return Poll::Ready(Ok(offset)); + } }, } }