5d360b
From 22f72cfdac645ac7a47289dbada48a116d19d42d Mon Sep 17 00:00:00 2001
5d360b
From: "Daniel P. Berrange" <berrange@redhat.com>
5d360b
Date: Thu, 8 Feb 2018 17:50:22 +0100
5d360b
Subject: [PATCH 08/27] vnc-jobs: move buffer reset, use new buffer move
5d360b
5d360b
RH-Author: Daniel P. Berrange <berrange@redhat.com>
5d360b
Message-id: <20180208175041.5634-9-berrange@redhat.com>
5d360b
Patchwork-id: 78938
5d360b
O-Subject: [RHEL-7.5 qemu-kvm PATCH v1 08/27] vnc-jobs: move buffer reset, use new buffer move
5d360b
Bugzilla: 1527405
5d360b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
5d360b
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
5d360b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
5d360b
From: Gerd Hoffmann <kraxel@redhat.com>
5d360b
5d360b
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
5d360b
Reviewed-by: Peter Lieven <pl@kamp.de>
5d360b
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
5d360b
Message-id: 1446203414-4013-10-git-send-email-kraxel@redhat.com
5d360b
(cherry picked from commit d90340115a3569caa72063775ff927f4dc353551)
5d360b
5d360b
 Conflicts:
5d360b
	ui/vnc-jobs.c - context differences
5d360b
	ui/vnc.{c.h} - make buffer_empty non-static since we don't
5d360b
	               have util/buffer.{c,h} yet
5d360b
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 ui/vnc-jobs.c | 15 ++++++++-------
5d360b
 ui/vnc.c      |  2 +-
5d360b
 ui/vnc.h      |  1 +
5d360b
 3 files changed, 10 insertions(+), 8 deletions(-)
5d360b
5d360b
diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
5d360b
index a6dfdf6..e553bd9 100644
5d360b
--- a/ui/vnc-jobs.c
5d360b
+++ b/ui/vnc-jobs.c
5d360b
@@ -29,6 +29,7 @@
5d360b
 #include "vnc.h"
5d360b
 #include "vnc-jobs.h"
5d360b
 #include "qemu/sockets.h"
5d360b
+#include "qemu/main-loop.h"
5d360b
 
5d360b
 /*
5d360b
  * Locking:
5d360b
@@ -164,8 +165,11 @@ void vnc_jobs_consume_buffer(VncState *vs)
5d360b
 
5d360b
     vnc_lock_output(vs);
5d360b
     if (vs->jobs_buffer.offset) {
5d360b
-        vnc_write(vs, vs->jobs_buffer.buffer, vs->jobs_buffer.offset);
5d360b
-        buffer_reset(&vs->jobs_buffer);
5d360b
+        if (vs->csock != -1 && buffer_empty(&vs->output)) {
5d360b
+            qemu_set_fd_handler(vs->csock, vnc_client_read,
5d360b
+                                vnc_client_write, vs);
5d360b
+        }
5d360b
+        buffer_move(&vs->output, &vs->jobs_buffer);
5d360b
     }
5d360b
     flush = vs->csock != -1 && vs->abort != true;
5d360b
     vnc_unlock_output(vs);
5d360b
@@ -192,8 +196,6 @@ static void vnc_async_encoding_start(VncState *orig, VncState *local)
5d360b
     local->hextile = orig->hextile;
5d360b
     local->zrle = orig->zrle;
5d360b
     local->csock = -1; /* Don't do any network work on this thread */
5d360b
-
5d360b
-    buffer_reset(&local->output);
5d360b
 }
5d360b
 
5d360b
 static void vnc_async_encoding_end(VncState *orig, VncState *local)
5d360b
@@ -269,14 +271,13 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
5d360b
 
5d360b
     vnc_lock_output(job->vs);
5d360b
     if (job->vs->csock != -1) {
5d360b
-        buffer_reserve(&job->vs->jobs_buffer, vs.output.offset);
5d360b
-        buffer_append(&job->vs->jobs_buffer, vs.output.buffer,
5d360b
-                      vs.output.offset);
5d360b
+        buffer_move(&job->vs->jobs_buffer, &vs.output);
5d360b
         /* Copy persistent encoding data */
5d360b
         vnc_async_encoding_end(job->vs, &vs);
5d360b
 
5d360b
 	qemu_bh_schedule(job->vs->bh);
5d360b
     }  else {
5d360b
+        buffer_reset(&vs.output);
5d360b
         /* Copy persistent encoding data */
5d360b
         vnc_async_encoding_end(job->vs, &vs);
5d360b
     }
5d360b
diff --git a/ui/vnc.c b/ui/vnc.c
5d360b
index 95457ad..ebb6484 100644
5d360b
--- a/ui/vnc.c
5d360b
+++ b/ui/vnc.c
5d360b
@@ -480,7 +480,7 @@ void buffer_reserve(Buffer *buffer, size_t len)
5d360b
     }
5d360b
 }
5d360b
 
5d360b
-static int buffer_empty(Buffer *buffer)
5d360b
+int buffer_empty(Buffer *buffer)
5d360b
 {
5d360b
     return buffer->offset == 0;
5d360b
 }
5d360b
diff --git a/ui/vnc.h b/ui/vnc.h
5d360b
index 703fef9..d8465ba 100644
5d360b
--- a/ui/vnc.h
5d360b
+++ b/ui/vnc.h
5d360b
@@ -547,6 +547,7 @@ void buffer_reset(Buffer *buffer);
5d360b
 void buffer_free(Buffer *buffer);
5d360b
 void buffer_append(Buffer *buffer, const void *data, size_t len);
5d360b
 void buffer_advance(Buffer *buf, size_t len);
5d360b
+int buffer_empty(Buffer *buffer);
5d360b
 uint8_t *buffer_end(Buffer *buffer);
5d360b
 void buffer_move_empty(Buffer *to, Buffer *from);
5d360b
 void buffer_move(Buffer *to, Buffer *from);
5d360b
-- 
5d360b
1.8.3.1
5d360b