Blob Blame History Raw
From f86c044ae075d142e658e866572eb0a37ecad2e1 Mon Sep 17 00:00:00 2001
From: Alon Levy <alevy@redhat.com>
Date: Thu, 22 Jul 2010 00:21:18 +0300
Subject: [PATCH 29/39] spice-vmc: split vmc_write to max sized virtio_serial_write calls

workaround for current windows driver limitation (RHBZ 617000)
---
 hw/spice-vmc.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/hw/spice-vmc.c b/hw/spice-vmc.c
index 041f243..b9d64a2 100644
--- a/hw/spice-vmc.c
+++ b/hw/spice-vmc.c
@@ -21,6 +21,8 @@
 #define VMC_GUEST_DEVICE_NAME "com.redhat.spice.0"
 #define VMC_DEVICE_NAME       "spicevmc"

+#define VMC_MAX_HOST_WRITE    2048
+
 #define dprintf(_svc, _level, _fmt, ...)                                \
     do {                                                                \
         static unsigned __dprintf_counter = 0;                          \
@@ -43,10 +45,23 @@ typedef struct SpiceVirtualChannel {
 static int vmc_write(SpiceVDIPortInstance *sin, const uint8_t *buf, int len)
 {
     SpiceVirtualChannel *svc = container_of(sin, SpiceVirtualChannel, sin);
-    ssize_t out;
+    ssize_t out = 0;
+    ssize_t last_out;
+    uint8_t* p = (uint8_t*)buf;
+
+    while (len > 0) {
+        last_out = virtio_serial_write(&svc->port, p,
+                            MIN(len, VMC_MAX_HOST_WRITE));
+        if (last_out > 0) {
+            out += last_out;
+            len -= last_out;
+            p += last_out;
+        } else {
+            break;
+        }
+    }

-    out = virtio_serial_write(&svc->port, buf, len);
-    dprintf(svc, 3, "%s: %lu/%d\n", __func__, out, len);
+    dprintf(svc, 3, "%s: %lu/%zd\n", __func__, out, len + out);
     return out;
 }

-- 
1.7.2.3