[spice-server,13/23] websocket: Fix updating remaining bytes to write in websocket_write

Submitted by Frediano Ziglio on June 25, 2019, 4:11 p.m.

Details

Message ID 20190625161147.25211-14-fziglio@redhat.com
State Accepted
Commit 0c2f386bebdf894ed4fc2ea46f9a9c0055e6d63b
Headers show
Series "WebSocket support" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio June 25, 2019, 4:11 p.m.
"len" is not always the full remainder (consider the case when
we are writing a partial frame).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 server/websocket.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/websocket.c b/server/websocket.c
index afb7502a1..dda71f768 100644
--- a/server/websocket.c
+++ b/server/websocket.c
@@ -478,10 +478,8 @@  int websocket_write(RedsWebSocket *ws, const void *buf, size_t len)
     }
 
     rc = ws->raw_write(ws->raw_stream, buf, len);
-    if (rc <= 0) {
-        ws->write_remainder = len;
-    } else {
-        ws->write_remainder = len - rc;
+    if (rc > 0) {
+        ws->write_remainder -= rc;
     }
     return rc;
 }