diff options
author | Hans de Goede <hdegoede@redhat.com> | 2011-07-19 10:56:19 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2012-11-01 16:39:57 +0100 |
commit | 3b5c0571d5c428cf1a661abb4b1e3473c5632f31 (patch) | |
tree | 667c52bd5908384b2a2cd4c939e12cbd84bf6a80 | |
parent | 46685086f0fff18f1ab9099001cf797cc4882cde (diff) |
usb-redir: Add flow control support
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | hw/usb/redirect.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 662e684ed..32b3dfc1a 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -239,8 +239,9 @@ static int usbredir_read(void *priv, uint8_t *data, int count) static int usbredir_write(void *priv, uint8_t *data, int count) { USBRedirDevice *dev = priv; + int r; - if (!dev->cs->opened) { + if (!dev->cs->opened || dev->cs->write_blocked) { return 0; } @@ -249,7 +250,16 @@ static int usbredir_write(void *priv, uint8_t *data, int count) return 0; } - return qemu_chr_fe_write(dev->cs, data, count); + r = qemu_chr_fe_write(dev->cs, data, count); + + if (r < 0) { + if (dev->cs->write_blocked) { + return 0; + } + return -1; + } + + return r; } /* @@ -1024,10 +1034,18 @@ static void usbredir_chardev_event(void *opaque, int event) } } +static void usbredir_chardev_write_unblocked(void *opaque) +{ + USBRedirDevice *dev = opaque; + + usbredirparser_do_write(dev->parser); +} + static const QemuChrHandlers usbredir_chr_handlers = { .fd_can_read = usbredir_chardev_can_read, .fd_read = usbredir_chardev_read, .fd_event = usbredir_chardev_event, + .fd_write_unblocked = usbredir_chardev_write_unblocked, }; /* |