diff mbox

[02/13] char-win: remove WinChardev.len

Message ID 20170509113332.4987-3-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau May 9, 2017, 11:33 a.m. UTC
The "len" argument can be passed directly to win_chr_read()

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 chardev/char-win.h |  1 -
 chardev/char-win.c | 16 +++++++---------
 2 files changed, 7 insertions(+), 10 deletions(-)

Comments

Philippe Mathieu-Daudé May 9, 2017, 12:47 p.m. UTC | #1
On 05/09/2017 08:33 AM, Marc-André Lureau wrote:
> The "len" argument can be passed directly to win_chr_read()
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  chardev/char-win.h |  1 -
>  chardev/char-win.c | 16 +++++++---------
>  2 files changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/chardev/char-win.h b/chardev/char-win.h
> index 73a0e3caef..70215e04c2 100644
> --- a/chardev/char-win.h
> +++ b/chardev/char-win.h
> @@ -32,7 +32,6 @@ typedef struct {
>      HANDLE hcom, hrecv, hsend;
>      OVERLAPPED orecv;
>      BOOL fpipe;
> -    DWORD len;
>
>      /* Protected by the Chardev chr_write_lock.  */
>      OVERLAPPED osend;
> diff --git a/chardev/char-win.c b/chardev/char-win.c
> index a46d878ef8..5e7daeeae1 100644
> --- a/chardev/char-win.c
> +++ b/chardev/char-win.c
> @@ -26,7 +26,7 @@
>  #include "qapi/error.h"
>  #include "char-win.h"
>
> -static void win_chr_read(Chardev *chr)
> +static void win_chr_read(Chardev *chr, DWORD len)
>  {
>      WinChardev *s = WIN_CHARDEV(chr);
>      int max_size = qemu_chr_be_can_write(chr);
> @@ -34,16 +34,16 @@ static void win_chr_read(Chardev *chr)
>      uint8_t buf[CHR_READ_BUF_LEN];
>      DWORD size;
>
> -    if (s->len > max_size) {
> -        s->len = max_size;
> +    if (len > max_size) {
> +        len = max_size;
>      }
> -    if (s->len == 0) {
> +    if (len == 0) {
>          return;
>      }
>
>      ZeroMemory(&s->orecv, sizeof(s->orecv));
>      s->orecv.hEvent = s->hrecv;
> -    ret = ReadFile(s->hcom, buf, s->len, &size, &s->orecv);
> +    ret = ReadFile(s->hcom, buf, len, &size, &s->orecv);
>      if (!ret) {
>          err = GetLastError();
>          if (err == ERROR_IO_PENDING) {
> @@ -65,8 +65,7 @@ static int win_chr_poll(void *opaque)
>
>      ClearCommError(s->hcom, &comerr, &status);
>      if (status.cbInQue > 0) {
> -        s->len = status.cbInQue;
> -        win_chr_read(chr);
> +        win_chr_read(chr, status.cbInQue);
>          return 1;
>      }
>      return 0;
> @@ -146,8 +145,7 @@ int win_chr_pipe_poll(void *opaque)
>
>      PeekNamedPipe(s->hcom, NULL, 0, NULL, &size, NULL);
>      if (size > 0) {
> -        s->len = size;
> -        win_chr_read(chr);
> +        win_chr_read(chr, size);
>          return 1;
>      }
>      return 0;
>
diff mbox

Patch

diff --git a/chardev/char-win.h b/chardev/char-win.h
index 73a0e3caef..70215e04c2 100644
--- a/chardev/char-win.h
+++ b/chardev/char-win.h
@@ -32,7 +32,6 @@  typedef struct {
     HANDLE hcom, hrecv, hsend;
     OVERLAPPED orecv;
     BOOL fpipe;
-    DWORD len;
 
     /* Protected by the Chardev chr_write_lock.  */
     OVERLAPPED osend;
diff --git a/chardev/char-win.c b/chardev/char-win.c
index a46d878ef8..5e7daeeae1 100644
--- a/chardev/char-win.c
+++ b/chardev/char-win.c
@@ -26,7 +26,7 @@ 
 #include "qapi/error.h"
 #include "char-win.h"
 
-static void win_chr_read(Chardev *chr)
+static void win_chr_read(Chardev *chr, DWORD len)
 {
     WinChardev *s = WIN_CHARDEV(chr);
     int max_size = qemu_chr_be_can_write(chr);
@@ -34,16 +34,16 @@  static void win_chr_read(Chardev *chr)
     uint8_t buf[CHR_READ_BUF_LEN];
     DWORD size;
 
-    if (s->len > max_size) {
-        s->len = max_size;
+    if (len > max_size) {
+        len = max_size;
     }
-    if (s->len == 0) {
+    if (len == 0) {
         return;
     }
 
     ZeroMemory(&s->orecv, sizeof(s->orecv));
     s->orecv.hEvent = s->hrecv;
-    ret = ReadFile(s->hcom, buf, s->len, &size, &s->orecv);
+    ret = ReadFile(s->hcom, buf, len, &size, &s->orecv);
     if (!ret) {
         err = GetLastError();
         if (err == ERROR_IO_PENDING) {
@@ -65,8 +65,7 @@  static int win_chr_poll(void *opaque)
 
     ClearCommError(s->hcom, &comerr, &status);
     if (status.cbInQue > 0) {
-        s->len = status.cbInQue;
-        win_chr_read(chr);
+        win_chr_read(chr, status.cbInQue);
         return 1;
     }
     return 0;
@@ -146,8 +145,7 @@  int win_chr_pipe_poll(void *opaque)
 
     PeekNamedPipe(s->hcom, NULL, 0, NULL, &size, NULL);
     if (size > 0) {
-        s->len = size;
-        win_chr_read(chr);
+        win_chr_read(chr, size);
         return 1;
     }
     return 0;