diff mbox

[2/6] spice-qemu-char: write to chardev whatever amount it can read

Message ID 1354281947-20227-3-git-send-email-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau Nov. 30, 2012, 1:25 p.m. UTC
The current code waits until the chardev can read MIN(len, VMC_MAX)
But some chardev may never reach than amount, in fact some of them
will only ever accept write of 1. Fix the min computation and remove
the VMC_MAX constant.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 spice-qemu-char.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Alon Levy Dec. 2, 2012, 10 a.m. UTC | #1
> The current code waits until the chardev can read MIN(len, VMC_MAX)
> But some chardev may never reach than amount, in fact some of them
> will only ever accept write of 1. Fix the min computation and remove
> the VMC_MAX constant.

Looks good to me.

> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  spice-qemu-char.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/spice-qemu-char.c b/spice-qemu-char.c
> index 09aa22d..665efd3 100644
> --- a/spice-qemu-char.c
> +++ b/spice-qemu-char.c
> @@ -14,8 +14,6 @@
>          }
>                                                                        \
>      } while (0)
>  
> -#define VMC_MAX_HOST_WRITE    2048
> -
>  typedef struct SpiceCharDriver {
>      CharDriverState*      chr;
>      SpiceCharDeviceInstance     sin;
> @@ -35,8 +33,8 @@ static int vmc_write(SpiceCharDeviceInstance *sin,
> const uint8_t *buf, int len)
>      uint8_t* p = (uint8_t*)buf;
>  
>      while (len > 0) {
> -        last_out = MIN(len, VMC_MAX_HOST_WRITE);
> -        if (qemu_chr_be_can_write(scd->chr) < last_out) {
> +        last_out = MIN(len, qemu_chr_be_can_write(scd->chr));
> +        if (last_out <= 0) {
>              break;
>          }
>          qemu_chr_be_write(scd->chr, p, last_out);
> --
> 1.7.11.7
> 
> 
>
diff mbox

Patch

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 09aa22d..665efd3 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -14,8 +14,6 @@ 
         }                                                               \
     } while (0)
 
-#define VMC_MAX_HOST_WRITE    2048
-
 typedef struct SpiceCharDriver {
     CharDriverState*      chr;
     SpiceCharDeviceInstance     sin;
@@ -35,8 +33,8 @@  static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
     uint8_t* p = (uint8_t*)buf;
 
     while (len > 0) {
-        last_out = MIN(len, VMC_MAX_HOST_WRITE);
-        if (qemu_chr_be_can_write(scd->chr) < last_out) {
+        last_out = MIN(len, qemu_chr_be_can_write(scd->chr));
+        if (last_out <= 0) {
             break;
         }
         qemu_chr_be_write(scd->chr, p, last_out);