1c30660
From 1e87b85766f9c18a2f9dffd289c0e56d640637c4 Mon Sep 17 00:00:00 2001
96a5f8d
From: Hans de Goede <hdegoede@redhat.com>
96a5f8d
Date: Tue, 19 Jul 2011 10:56:19 +0200
96a5f8d
Subject: [PATCH] usb-redir: Add flow control support
96a5f8d
96a5f8d
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
96a5f8d
---
96a5f8d
 hw/usb/redirect.c | 22 ++++++++++++++++++++--
96a5f8d
 1 file changed, 20 insertions(+), 2 deletions(-)
96a5f8d
96a5f8d
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
96a5f8d
index bb07c62..4d23b66 100644
96a5f8d
--- a/hw/usb/redirect.c
96a5f8d
+++ b/hw/usb/redirect.c
96a5f8d
@@ -257,8 +257,9 @@ static int usbredir_read(void *priv, uint8_t *data, int count)
96a5f8d
 static int usbredir_write(void *priv, uint8_t *data, int count)
96a5f8d
 {
96a5f8d
     USBRedirDevice *dev = priv;
96a5f8d
+    int r;
96a5f8d
 
96a5f8d
-    if (!dev->cs->opened) {
96a5f8d
+    if (!dev->cs->opened || dev->cs->write_blocked) {
96a5f8d
         return 0;
96a5f8d
     }
96a5f8d
 
96a5f8d
@@ -267,7 +268,16 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
96a5f8d
         return 0;
96a5f8d
     }
96a5f8d
 
96a5f8d
-    return qemu_chr_fe_write(dev->cs, data, count);
96a5f8d
+    r = qemu_chr_fe_write(dev->cs, data, count);
96a5f8d
+
96a5f8d
+    if (r < 0) {
96a5f8d
+        if (dev->cs->write_blocked) {
96a5f8d
+           return 0;
96a5f8d
+        }
96a5f8d
+        return -1;
96a5f8d
+    }
96a5f8d
+
96a5f8d
+    return r;
96a5f8d
 }
96a5f8d
 
96a5f8d
 /*
96a5f8d
@@ -1227,10 +1237,18 @@ static void usbredir_chardev_event(void *opaque, int event)
96a5f8d
     }
96a5f8d
 }
96a5f8d
 
96a5f8d
+static void usbredir_chardev_write_unblocked(void *opaque)
96a5f8d
+{
96a5f8d
+    USBRedirDevice *dev = opaque;
96a5f8d
+
96a5f8d
+    usbredirparser_do_write(dev->parser);
96a5f8d
+}
96a5f8d
+
96a5f8d
 static const QemuChrHandlers usbredir_chr_handlers = {
96a5f8d
     .fd_can_read = usbredir_chardev_can_read,
96a5f8d
     .fd_read = usbredir_chardev_read,
96a5f8d
     .fd_event = usbredir_chardev_event,
96a5f8d
+    .fd_write_unblocked = usbredir_chardev_write_unblocked,
96a5f8d
 };
96a5f8d
 
96a5f8d
 /*