diff mbox

[01/13] char-win: simplify win_chr_read()

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

Commit Message

Marc-André Lureau May 9, 2017, 11:33 a.m. UTC
win_chr_read_poll() is always used before win_chr_read().
We can easily fold win_chr_readfile() too.

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

Comments

Philippe Mathieu-Daudé May 9, 2017, 12:55 p.m. UTC | #1
On 05/09/2017 08:33 AM, Marc-André Lureau wrote:
> win_chr_read_poll() is always used before win_chr_read().
> We can easily fold win_chr_readfile() too.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

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

> ---
>  chardev/char-win.h |  2 +-
>  chardev/char-win.c | 35 +++++++++--------------------------
>  2 files changed, 10 insertions(+), 27 deletions(-)
>
> diff --git a/chardev/char-win.h b/chardev/char-win.h
> index d78a7d7972..73a0e3caef 100644
> --- a/chardev/char-win.h
> +++ b/chardev/char-win.h
> @@ -28,7 +28,7 @@
>
>  typedef struct {
>      Chardev parent;
> -    int max_size;
> +
>      HANDLE hcom, hrecv, hsend;
>      OVERLAPPED orecv;
>      BOOL fpipe;
> diff --git a/chardev/char-win.c b/chardev/char-win.c
> index e4b6957ded..a46d878ef8 100644
> --- a/chardev/char-win.c
> +++ b/chardev/char-win.c
> @@ -26,14 +26,21 @@
>  #include "qapi/error.h"
>  #include "char-win.h"
>
> -static void win_chr_readfile(Chardev *chr)
> +static void win_chr_read(Chardev *chr)
>  {
>      WinChardev *s = WIN_CHARDEV(chr);
> -
> +    int max_size = qemu_chr_be_can_write(chr);
>      int ret, err;
>      uint8_t buf[CHR_READ_BUF_LEN];
>      DWORD size;
>
> +    if (s->len > max_size) {
> +        s->len = max_size;
> +    }
> +    if (s->len == 0) {
> +        return;
> +    }
> +
>      ZeroMemory(&s->orecv, sizeof(s->orecv));
>      s->orecv.hEvent = s->hrecv;
>      ret = ReadFile(s->hcom, buf, s->len, &size, &s->orecv);
> @@ -49,28 +56,6 @@ static void win_chr_readfile(Chardev *chr)
>      }
>  }
>
> -static void win_chr_read(Chardev *chr)
> -{
> -    WinChardev *s = WIN_CHARDEV(chr);
> -
> -    if (s->len > s->max_size) {
> -        s->len = s->max_size;
> -    }
> -    if (s->len == 0) {
> -        return;
> -    }
> -
> -    win_chr_readfile(chr);
> -}
> -
> -static int win_chr_read_poll(Chardev *chr)
> -{
> -    WinChardev *s = WIN_CHARDEV(chr);
> -
> -    s->max_size = qemu_chr_be_can_write(chr);
> -    return s->max_size;
> -}
> -
>  static int win_chr_poll(void *opaque)
>  {
>      Chardev *chr = CHARDEV(opaque);
> @@ -81,7 +66,6 @@ static int win_chr_poll(void *opaque)
>      ClearCommError(s->hcom, &comerr, &status);
>      if (status.cbInQue > 0) {
>          s->len = status.cbInQue;
> -        win_chr_read_poll(chr);
>          win_chr_read(chr);
>          return 1;
>      }
> @@ -163,7 +147,6 @@ int win_chr_pipe_poll(void *opaque)
>      PeekNamedPipe(s->hcom, NULL, 0, NULL, &size, NULL);
>      if (size > 0) {
>          s->len = size;
> -        win_chr_read_poll(chr);
>          win_chr_read(chr);
>          return 1;
>      }
>
diff mbox

Patch

diff --git a/chardev/char-win.h b/chardev/char-win.h
index d78a7d7972..73a0e3caef 100644
--- a/chardev/char-win.h
+++ b/chardev/char-win.h
@@ -28,7 +28,7 @@ 
 
 typedef struct {
     Chardev parent;
-    int max_size;
+
     HANDLE hcom, hrecv, hsend;
     OVERLAPPED orecv;
     BOOL fpipe;
diff --git a/chardev/char-win.c b/chardev/char-win.c
index e4b6957ded..a46d878ef8 100644
--- a/chardev/char-win.c
+++ b/chardev/char-win.c
@@ -26,14 +26,21 @@ 
 #include "qapi/error.h"
 #include "char-win.h"
 
-static void win_chr_readfile(Chardev *chr)
+static void win_chr_read(Chardev *chr)
 {
     WinChardev *s = WIN_CHARDEV(chr);
-
+    int max_size = qemu_chr_be_can_write(chr);
     int ret, err;
     uint8_t buf[CHR_READ_BUF_LEN];
     DWORD size;
 
+    if (s->len > max_size) {
+        s->len = max_size;
+    }
+    if (s->len == 0) {
+        return;
+    }
+
     ZeroMemory(&s->orecv, sizeof(s->orecv));
     s->orecv.hEvent = s->hrecv;
     ret = ReadFile(s->hcom, buf, s->len, &size, &s->orecv);
@@ -49,28 +56,6 @@  static void win_chr_readfile(Chardev *chr)
     }
 }
 
-static void win_chr_read(Chardev *chr)
-{
-    WinChardev *s = WIN_CHARDEV(chr);
-
-    if (s->len > s->max_size) {
-        s->len = s->max_size;
-    }
-    if (s->len == 0) {
-        return;
-    }
-
-    win_chr_readfile(chr);
-}
-
-static int win_chr_read_poll(Chardev *chr)
-{
-    WinChardev *s = WIN_CHARDEV(chr);
-
-    s->max_size = qemu_chr_be_can_write(chr);
-    return s->max_size;
-}
-
 static int win_chr_poll(void *opaque)
 {
     Chardev *chr = CHARDEV(opaque);
@@ -81,7 +66,6 @@  static int win_chr_poll(void *opaque)
     ClearCommError(s->hcom, &comerr, &status);
     if (status.cbInQue > 0) {
         s->len = status.cbInQue;
-        win_chr_read_poll(chr);
         win_chr_read(chr);
         return 1;
     }
@@ -163,7 +147,6 @@  int win_chr_pipe_poll(void *opaque)
     PeekNamedPipe(s->hcom, NULL, 0, NULL, &size, NULL);
     if (size > 0) {
         s->len = size;
-        win_chr_read_poll(chr);
         win_chr_read(chr);
         return 1;
     }