Skip to contentSkip to conversation

fix monitor

PATCH Applied Gerd Hoffmann 3 participants 3 messages Mar 19, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix monitor

chardev flow control broke monitor, fix it by adding watch support.

---
 monitor.c |   23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
monitor.c +21 -2
index 112e920..680d344 100644
@@ -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);
     }
 }
 
Signature · 1 line
1.7.9.7
#1 lore raw

Hi,

Looks good, one minor nitpick.

Quoted 25 lines · Gerd Hoffmann

chardev flow control broke monitor, fix it by adding watch support.

---
  monitor.c |   23 +++++++++++++++++++++--
  1 file changed, 21 insertions(+), 2 deletions(-)
monitor.c +9 -0
index 112e920..680d344 100644
@@ -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) {

monitor.c int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, · line 283

Quoted 10 lines
monitor.c +8 -2
-        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 */

Typo in the comment.

monitor.c int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, · line 290

Quoted 8 lines
monitor.c +4 -0
+            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);
      }
  }
 

Regards,

Hans