]> git.proxmox.com Git - qemu.git/commitdiff
fix monitor
authorGerd Hoffmann <kraxel@redhat.com>
Tue, 19 Mar 2013 09:57:56 +0000 (10:57 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 19 Mar 2013 12:52:10 +0000 (07:52 -0500)
chardev flow control broke monitor, fix it by adding watch support.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
monitor.c

index 112e92064d4cc957805127c67f114100adbfade0..680d344211e2f6a3299a649d962e2cc816effc42 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -261,11 +261,30 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
     }
 }
 
+static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond,
+                                  void *opaque)
+{
+    monitor_flush(opaque);
+    return FALSE;
+}
+
 void monitor_flush(Monitor *mon)
 {
+    int rc;
+
     if (mon && mon->outbuf_index != 0 && !mon->mux_out) {
-        qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
-        mon->outbuf_index = 0;
+        rc = qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
+        if (rc == mon->outbuf_index) {
+            /* all flushed */
+            mon->outbuf_index = 0;
+            return;
+        }
+        if (rc > 0) {
+            /* partinal write */
+            memmove(mon->outbuf, mon->outbuf + rc, mon->outbuf_index - rc);
+            mon->outbuf_index -= rc;
+        }
+        qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked, mon);
     }
 }