fc5c27
>From e7903f889f3105efe7e3876925926e8e91919b0f Mon Sep 17 00:00:00 2001
3f1f29
From: Hans de Goede <hdegoede@redhat.com>
3f1f29
Date: Tue, 19 Jul 2011 10:56:19 +0200
fc5c27
Subject: [PATCH 11/28] usb-redir: Add flow control support
3f1f29
3f1f29
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
3f1f29
---
3f1f29
 usb-redir.c |   28 +++++++++++++++++++++++++++-
3f1f29
 1 files changed, 27 insertions(+), 1 deletions(-)
3f1f29
3f1f29
diff --git a/usb-redir.c b/usb-redir.c
3f1f29
index e2b5a2c..6932beb 100644
3f1f29
--- a/usb-redir.c
3f1f29
+++ b/usb-redir.c
3f1f29
@@ -224,8 +224,22 @@ static int usbredir_read(void *priv, uint8_t *data, int count)
3f1f29
 static int usbredir_write(void *priv, uint8_t *data, int count)
3f1f29
 {
3f1f29
     USBRedirDevice *dev = priv;
3f1f29
+    int r;
3f1f29
 
3f1f29
-    return qemu_chr_write(dev->cs, data, count);
3f1f29
+    if (dev->cs->write_blocked) {
3f1f29
+        return 0;
3f1f29
+    }
3f1f29
+
3f1f29
+    r = qemu_chr_write(dev->cs, data, count);
3f1f29
+
3f1f29
+    if (r < 0) {
3f1f29
+        if (dev->cs->write_blocked) {
3f1f29
+            return 0;
3f1f29
+        }
3f1f29
+        return -1;
3f1f29
+    }
3f1f29
+
3f1f29
+    return r;
3f1f29
 }
3f1f29
 
3f1f29
 /*
3f1f29
@@ -782,10 +796,22 @@ static void usbredir_chardev_event(void *opaque, int event)
3f1f29
     }
3f1f29
 }
3f1f29
 
3f1f29
+static void usbredir_chardev_write_unblocked(void *opaque)
3f1f29
+{
3f1f29
+    USBRedirDevice *dev = opaque;
3f1f29
+
3f1f29
+    if (dev->parser == NULL) {
3f1f29
+        /* usbredir_open_close_bh hasn't handled the open event yet */
3f1f29
+        return;
3f1f29
+    }
3f1f29
+    usbredirparser_do_write(dev->parser);
3f1f29
+}
3f1f29
+
3f1f29
 static const QemuChrHandlers usbredir_chr_handlers = {
3f1f29
     .fd_can_read = usbredir_chardev_can_read,
3f1f29
     .fd_read = usbredir_chardev_read,
3f1f29
     .fd_event = usbredir_chardev_event,
3f1f29
+    .fd_write_unblocked = usbredir_chardev_write_unblocked,
3f1f29
 };
3f1f29
 
3f1f29
 /*
3f1f29
-- 
3f1f29
1.7.5.1
3f1f29