All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, eblake@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH v3 15/21] char-udp: flush as much buffer as possible
Date: Thu, 16 Mar 2017 13:21:15 +0400	[thread overview]
Message-ID: <20170316092121.25672-16-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20170316092121.25672-1-marcandre.lureau@redhat.com>

Instead of flushing the buffer byte by byte, call qemu_chr_be_write()
with as much byte possible accepted by the front-end.

Factor out buffer flushing in a common function udp_chr_flush_buffer().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 chardev/char-udp.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/chardev/char-udp.c b/chardev/char-udp.c
index 804bd22efa..1958c36de4 100644
--- a/chardev/char-udp.c
+++ b/chardev/char-udp.c
@@ -51,6 +51,18 @@ static int udp_chr_write(Chardev *chr, const uint8_t *buf, int len)
         s->ioc, (const char *)buf, len, NULL);
 }
 
+static void udp_chr_flush_buffer(UdpChardev *s)
+{
+    Chardev *chr = CHARDEV(s);
+
+    while (s->max_size > 0 && s->bufptr < s->bufcnt) {
+        int n = MIN(s->max_size, s->bufcnt - s->bufptr);
+        qemu_chr_be_write(chr, &s->buf[s->bufptr], n);
+        s->bufptr += n;
+        s->max_size = qemu_chr_be_can_write(chr);
+    }
+}
+
 static int udp_chr_read_poll(void *opaque)
 {
     Chardev *chr = CHARDEV(opaque);
@@ -61,11 +73,8 @@ static int udp_chr_read_poll(void *opaque)
     /* If there were any stray characters in the queue process them
      * first
      */
-    while (s->max_size > 0 && s->bufptr < s->bufcnt) {
-        qemu_chr_be_write(chr, &s->buf[s->bufptr], 1);
-        s->bufptr++;
-        s->max_size = qemu_chr_be_can_write(chr);
-    }
+    udp_chr_flush_buffer(s);
+
     return s->max_size;
 }
 
@@ -85,13 +94,8 @@ static gboolean udp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
         return FALSE;
     }
     s->bufcnt = ret;
-
     s->bufptr = 0;
-    while (s->max_size > 0 && s->bufptr < s->bufcnt) {
-        qemu_chr_be_write(chr, &s->buf[s->bufptr], 1);
-        s->bufptr++;
-        s->max_size = qemu_chr_be_can_write(chr);
-    }
+    udp_chr_flush_buffer(s);
 
     return TRUE;
 }
-- 
2.12.0.191.gc5d8de91d

  parent reply	other threads:[~2017-03-16  9:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16  9:21 [Qemu-devel] [PATCH v3 00/21] chardev clean-ups & tests (after 2.9) Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 01/21] char: remove qemu_chr_be_generic_open Marc-André Lureau
2017-04-04 15:08   ` Philippe Mathieu-Daudé
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 02/21] mux: simplfy muxes_realize_done Marc-André Lureau
2017-04-04 15:14   ` Philippe Mathieu-Daudé
2017-04-04 16:31     ` Marc-André Lureau
2017-04-11  3:02       ` Philippe Mathieu-Daudé
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 03/21] xen: use a better chardev type check Marc-André Lureau
2017-04-04 15:15   ` Philippe Mathieu-Daudé
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 04/21] container: don't leak container reference Marc-André Lureau
2017-04-11  2:53   ` Philippe Mathieu-Daudé
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 05/21] char: add a /chardevs container Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 06/21] vl: add todo note about root container cleanup Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 07/21] char: use /chardevs container instead of chardevs list Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 08/21] char: remove qemu_chardev_add Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 09/21] char: remove chardevs list Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 10/21] char: useless NULL check Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 11/21] char-socket: introduce update_disconnected_filename() Marc-André Lureau
2017-04-11  2:56   ` Philippe Mathieu-Daudé
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 12/21] char-socket: update local address after listen Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 13/21] char-socket: add 'addr' property Marc-André Lureau
2017-04-11  2:57   ` Philippe Mathieu-Daudé
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 14/21] char-socket: add 'connected' property Marc-André Lureau
2017-04-11  2:58   ` Philippe Mathieu-Daudé
2017-03-16  9:21 ` Marc-André Lureau [this message]
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 16/21] tests: add alias check in /char/ringbuf Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 17/21] tests: add /char/pipe test Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 18/21] tests: add /char/file test Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 19/21] tests: add /char/socket test Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 20/21] tests: add /char/udp test Marc-André Lureau
2017-03-16  9:21 ` [Qemu-devel] [PATCH v3 21/21] tests: add /char/console test Marc-André Lureau
2017-04-10 13:58 ` [Qemu-devel] [PATCH v3 00/21] chardev clean-ups & tests (after 2.9) Marc-André Lureau
2017-04-18  9:50   ` Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170316092121.25672-16-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=eblake@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.