diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2016-12-23 14:55:54 +0100 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2017-05-04 15:34:41 +0400 |
commit | e0b6767b6c56a08827e35873e7d259d08e4b3ee5 (patch) | |
tree | cbce4612aeaafaaada44f6ad48376eccad8cb5bc | |
parent | da2d19b080f6214b646a9f250760f5f41adcd21b (diff) |
char-udp: flush as much buffer as possible
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>
-rw-r--r-- | chardev/char-udp.c | 26 |
1 files 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; } |