From 6baef17ecf1ed994cfc8038bc610e8b7ff88506a Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Tue, 14 Jul 2009 14:18:54 +0200 Subject: Fixes bug in CLI TX buffer management. --- sysdep/unix/main.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'sysdep') diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 5f5b165..17845d2 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -178,22 +178,44 @@ cmd_reconfig(char *name, int type) static sock *cli_sk; static char *path_control_socket = PATH_CONTROL_SOCKET; -int + +static void cli_write(cli *c) { sock *s = c->priv; - if (c->tx_pos) + while (c->tx_pos) { struct cli_out *o = c->tx_pos; + + int len = o->wpos - o->outpos; s->tbuf = o->outpos; - if (sk_send(s, o->wpos - o->outpos) > 0) - { - c->tx_pos = o->next; - ev_schedule(c->event); - } + o->outpos = o->wpos; + + if (sk_send(s, len) <= 0) + return; + + c->tx_pos = o->next; } - return !c->tx_pos; + + /* Everything is written */ + s->tbuf = NULL; + cli_written(c); +} + +void +cli_write_trigger(cli *c) +{ + sock *s = c->priv; + + if (s->tbuf == NULL) + cli_write(c); +} + +static void +cli_tx(sock *s) +{ + cli_write(s->data); } int @@ -232,15 +254,6 @@ cli_rx(sock *s, int size UNUSED) return 0; } -static void -cli_tx(sock *s) -{ - cli *c = s->data; - - if (cli_write(c)) - cli_written(c); -} - static void cli_err(sock *s, int err) { -- cgit v1.2.3