Skip to contentSkip to conversation

ui/gtk: retry sending VTE console input

PATCH In review Volker Rümelin 3 participants 3 messages Aug 10, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/gtk: retry sending VTE console input

Commit 584af1f1d9 ("ui/gtk: add a keyboard fifo to the VTE consoles") changed the VTE chardev backend code to rely on the chr_accept_input() callback function. The code expects a chr_accept_input() call whenever qemu_chr_be_can_write() bytes were written. It turns out this is wrong. Some chardev frontends only call this callback after can_write was 0.

Change the code to send data until the keyboard fifo is empty or qemu_chr_be_can_write() returns 0.

Fixes 584af1f1d9 ("ui/gtk: add a keyboard fifo to the VTE consoles")
---
 ui/gtk.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
ui/gtk.c +4 -6
index 974e4dfc0b..cfb0728d1f 100644
@@ -1646,16 +1646,14 @@ static void gd_vc_send_chars(VirtualConsole *vc)
 
     len = qemu_chr_be_can_write(vc->vte.chr);
     avail = fifo8_num_used(&vc->vte.out_fifo);
-    if (len > avail) {
-        len = avail;
-    }
-    while (len > 0) {
+    while (len > 0 && avail > 0) {
         const uint8_t *buf;
         uint32_t size;
 
-        buf = fifo8_pop_buf(&vc->vte.out_fifo, len, &size);
+        buf = fifo8_pop_buf(&vc->vte.out_fifo, MIN(len, avail), &size);
         qemu_chr_be_write(vc->vte.chr, (uint8_t *)buf, size);
-        len -= size;
+        len = qemu_chr_be_can_write(vc->vte.chr);
+        avail -= size;
     }
 }
 
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Volker Rümelin

Commit 584af1f1d9 ("ui/gtk: add a keyboard fifo to the VTE consoles") changed the VTE chardev backend code to rely on the chr_accept_input() callback function. The code expects a chr_accept_input() call whenever qemu_chr_be_can_write() bytes were written. It turns out this is wrong. Some chardev frontends only call this callback after can_write was 0.

Quoted 6 lines

Change the code to send data until the keyboard fifo is empty or qemu_chr_be_can_write() returns 0.

Fixes 584af1f1d9 ("ui/gtk: add a keyboard fifo to the VTE consoles")

---

Quoted 32 lines
 ui/gtk.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
ui/gtk.c +4 -7
index 974e4dfc0b..cfb0728d1f 100644
@@ -1646,16 +1646,14 @@ static void gd_vc_send_chars(VirtualConsole *vc)
 
     len = qemu_chr_be_can_write(vc->vte.chr);
     avail = fifo8_num_used(&vc->vte.out_fifo);
-    if (len > avail) {
-        len = avail;
-    }
-    while (len > 0) {
+    while (len > 0 && avail > 0) {
         const uint8_t *buf;
         uint32_t size;
 
-        buf = fifo8_pop_buf(&vc->vte.out_fifo, len, &size);
+        buf = fifo8_pop_buf(&vc->vte.out_fifo, MIN(len, avail), &size);
         qemu_chr_be_write(vc->vte.chr, (uint8_t *)buf, size);
-        len -= size;
+        len = qemu_chr_be_can_write(vc->vte.chr);
+        avail -= size;
     }
 }
 
--

2.26.2

Signature · 1 line
Marc-André Lureau
#2 lore raw
In reply to Volker Rümelin
Quoted 7 lines · Volker Rümelin

Commit 584af1f1d9 ("ui/gtk: add a keyboard fifo to the VTE consoles") changed the VTE chardev backend code to rely on the chr_accept_input() callback function. The code expects a chr_accept_input() call whenever qemu_chr_be_can_write() bytes were written. It turns out this is wrong. Some chardev frontends only call this callback after can_write was 0.

Quoted 5 lines

Change the code to send data until the keyboard fifo is empty or qemu_chr_be_can_write() returns 0.

Fixes 584af1f1d9 ("ui/gtk: add a keyboard fifo to the VTE consoles")

Queued.

thanks,
Gerd