All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] io: fix decoding when multiple websockets frames arrive at once
@ 2017-01-30 10:51 Daniel P. Berrange
  2017-01-30 17:20 ` Eric Blake
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel P. Berrange @ 2017-01-30 10:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Brian Rak, Daniel P. Berrange

The qio_channel_websock_read_wire() method will read upto 4096
bytes off the socket and then decode the websockets header and
payload. The code was only decoding a single websockets frame,
even if the buffered data contained multiple frames. This meant
that decoding of subsequent frames was delayed until further
input arrived on the socket. This backlog of delayed frames
gets worse & worse over time.

Symptom was that when connecting to the VNC server via the
built-in websockets server, mouse/keyboard interaction would
start out fine, but slowly get more & more delayed until it
was unusable.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 io/channel-websock.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/io/channel-websock.c b/io/channel-websock.c
index e47279a..a06a4a8 100644
--- a/io/channel-websock.c
+++ b/io/channel-websock.c
@@ -570,21 +570,24 @@ static ssize_t qio_channel_websock_read_wire(QIOChannelWebsock *ioc,
         ioc->encinput.offset += ret;
     }
 
-    if (ioc->payload_remain == 0) {
-        ret = qio_channel_websock_decode_header(ioc, errp);
+    while (ioc->encinput.offset != 0) {
+        if (ioc->payload_remain == 0) {
+            ret = qio_channel_websock_decode_header(ioc, errp);
+            if (ret < 0) {
+                return ret;
+            }
+            if (ret == 0) {
+                ioc->io_eof = TRUE;
+                break;
+            }
+        }
+
+        ret = qio_channel_websock_decode_payload(ioc, errp);
         if (ret < 0) {
             return ret;
         }
-        if (ret == 0) {
-            return 0;
-        }
     }
-
-    ret = qio_channel_websock_decode_payload(ioc, errp);
-    if (ret < 0) {
-        return ret;
-    }
-    return ret;
+    return 1;
 }
 
 
@@ -642,9 +645,6 @@ static gboolean qio_channel_websock_flush(QIOChannel *ioc,
         if (ret < 0) {
             goto cleanup;
         }
-        if (ret == 0) {
-            wioc->io_eof = TRUE;
-        }
     }
 
  cleanup:
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] io: fix decoding when multiple websockets frames arrive at once
  2017-01-30 10:51 [Qemu-devel] [PATCH] io: fix decoding when multiple websockets frames arrive at once Daniel P. Berrange
@ 2017-01-30 17:20 ` Eric Blake
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2017-01-30 17:20 UTC (permalink / raw)
  To: Daniel P. Berrange, qemu-devel; +Cc: Brian Rak

[-- Attachment #1: Type: text/plain, Size: 1050 bytes --]

On 01/30/2017 04:51 AM, Daniel P. Berrange wrote:
> The qio_channel_websock_read_wire() method will read upto 4096

s/upto/up to/

> bytes off the socket and then decode the websockets header and
> payload. The code was only decoding a single websockets frame,
> even if the buffered data contained multiple frames. This meant
> that decoding of subsequent frames was delayed until further
> input arrived on the socket. This backlog of delayed frames
> gets worse & worse over time.
> 
> Symptom was that when connecting to the VNC server via the
> built-in websockets server, mouse/keyboard interaction would
> start out fine, but slowly get more & more delayed until it
> was unusable.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  io/channel-websock.c | 28 ++++++++++++++--------------
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-30 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-30 10:51 [Qemu-devel] [PATCH] io: fix decoding when multiple websockets frames arrive at once Daniel P. Berrange
2017-01-30 17:20 ` Eric Blake

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.