Skip to content

Commit

Permalink
char-udp: flush as much buffer as possible
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
  • Loading branch information
elmarco committed May 4, 2017
1 parent da2d19b commit e0b6767
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions chardev/char-udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down

0 comments on commit e0b6767

Please sign in to comment.