[Spice-devel] [PATCH spice-server 1/2] test-stream-device: Better Qemu emulation for data reading

Frediano Ziglio fziglio at redhat.com
Wed Dec 6 16:53:24 UTC 2017


Qemu does not trigger a new data read if we don't read all data in
the buffer.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/stream-device.c            | 6 ++++++
 server/tests/test-stream-device.c | 8 ++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

Maybe would be better to use a loop inside stream_device_read_msg_from_dev
instead of calling red_char_device_wakeup ?

diff --git a/server/stream-device.c b/server/stream-device.c
index 4eaa959b..18fee2e8 100644
--- a/server/stream-device.c
+++ b/server/stream-device.c
@@ -123,6 +123,12 @@ stream_device_read_msg_from_dev(RedCharDevice *self, SpiceCharDeviceInstance *si
         dev->hdr_pos = 0;
     }
 
+    // Qemu put the device on blocking state if we don't read all data
+    // so schedule another read.
+    // We arrive here only if we have an error or we are reading data
+    // so we can't cause a tighly loop here
+    red_char_device_wakeup(self);
+
     return NULL;
 }
 
diff --git a/server/tests/test-stream-device.c b/server/tests/test-stream-device.c
index 656bf56b..f937e30b 100644
--- a/server/tests/test-stream-device.c
+++ b/server/tests/test-stream-device.c
@@ -68,8 +68,12 @@ static int vmc_read(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin,
     pos += ret;
     // kick off next message read
     // currently Qemu kicks the device so we need to do it manually
-    // here
-    spice_server_char_device_wakeup(&vmc_instance);
+    // here. If not all data are read the device goes into blocking
+    // state and we get the wake only when we read from the device
+    // again
+    if (pos >= *message_sizes_curr) {
+        spice_server_char_device_wakeup(&vmc_instance);
+    }
     return ret;
 }
 
-- 
2.14.3



More information about the Spice-devel mailing list