252f3a
>From 7a9e7aaa30abf42879d3f13b41679513045c31ec Mon Sep 17 00:00:00 2001
252f3a
From: Hans de Goede <hdegoede@redhat.com>
252f3a
Date: Tue, 22 Mar 2011 16:28:41 +0100
252f3a
Subject: [PATCH 18/18] spice-qemu-char: Fix flow control in client -> guest direction
252f3a
252f3a
In the old spice-vmc device we used to have:
252f3a
last_out = virtio_serial_write(&svc->port, p, MIN(len, VMC_MAX_HOST_WRITE));
252f3a
if (last_out > 0)
252f3a
   ...
252f3a
252f3a
Now in the chardev backend we have:
252f3a
last_out = MIN(len, VMC_MAX_HOST_WRITE);
252f3a
qemu_chr_read(scd->chr, p, last_out);
252f3a
if (last_out > 0) {
252f3a
   ...
252f3a
252f3a
Which causes us to no longer detect if the virtio port is not ready
252f3a
to receive data from us. chardev actually has a mechanism to detect this,
252f3a
but it requires a separate call to qemu_chr_can_read, before calling
252f3a
qemu_chr_read (which return void).
252f3a
252f3a
This patch uses qemu_chr_can_read to fix the flow control from client to
252f3a
guest.
252f3a
252f3a
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
252f3a
---
252f3a
 spice-qemu-char.c |   11 +++++------
252f3a
 1 files changed, 5 insertions(+), 6 deletions(-)
252f3a
252f3a
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
252f3a
index 343146c..def713a 100644
252f3a
--- a/spice-qemu-char.c
252f3a
+++ b/spice-qemu-char.c
252f3a
@@ -38,14 +38,13 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
252f3a
 
252f3a
     while (len > 0) {
252f3a
         last_out = MIN(len, VMC_MAX_HOST_WRITE);
252f3a
-        qemu_chr_read(scd->chr, p, last_out);
252f3a
-        if (last_out > 0) {
252f3a
-            out += last_out;
252f3a
-            len -= last_out;
252f3a
-            p += last_out;
252f3a
-        } else {
252f3a
+        if (qemu_chr_can_read(scd->chr) < last_out) {
252f3a
             break;
252f3a
         }
252f3a
+        qemu_chr_read(scd->chr, p, last_out);
252f3a
+        out += last_out;
252f3a
+        len -= last_out;
252f3a
+        p += last_out;
252f3a
     }
252f3a
 
252f3a
     dprintf(scd, 3, "%s: %lu/%zd\n", __func__, out, len + out);
252f3a
-- 
252f3a
1.7.3.2
252f3a