From 5d37dac78594f4c3aa23e49cdca532a21674498a Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 22 Nov 2018 10:58:42 +0100 Subject: [PATCH] MINOR: mux-h1: Consume channel's data in a loop in h1_snd_buf() In h1_snd_buf(), the data sending is done synchronously, as much as possible. So if some data remains in the channel's buffer, because there was not enougth place in the output buffer, it may be good the retry after a send because some space may have been released when sending. Most of time the output buffer is empty and all channel's data are consumed the first time. And if no data are sent, we don't retry to do more. So the loop is just here to optimize edge cases without any cost for all others. --- src/mux_h1.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/mux_h1.c b/src/mux_h1.c index 6c104f309..b70afa7ae 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -1784,36 +1784,39 @@ static size_t h1_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t coun { struct h1s *h1s = cs->ctx; struct h1c *h1c; - size_t ret = 0; + size_t total = 0; if (!h1s) - return ret; + return 0; h1c = h1s->h1c; - if (h1c->flags & H1C_F_CS_WAIT_CONN) return 0; - if (!(h1c->flags & (H1C_F_OUT_FULL|H1C_F_OUT_ALLOC))) - ret = h1_process_output(h1c, buf, count); - if (ret > 0) { - h1_send(h1c); + while (total != count) { + size_t ret = 0; - /* We need to do that because of the infinite forwarding. - * contains HTX messages so when infinite forwarding is enabled, - * count is equal to the buffer size. From outside, the buffer - * appears as full. - */ - if (!b_data(buf)) - ret = count; + if (!(h1c->flags & (H1C_F_OUT_FULL|H1C_F_OUT_ALLOC))) + ret = h1_process_output(h1c, buf, count); + if (!ret) + break; + total += ret; + if (!h1_send(h1c)) + break; } - if (count && ret != count) { + /* We need to do that because of the infinite forwarding. + * contains HTX messages so when infinite forwarding is enabled, + * count is equal to the buffer size. From outside, the buffer + * appears as full. + */ + if (!b_data(buf)) + total = count; + else if (total != count) { if (!(h1c->wait_event.wait_reason & SUB_CAN_SEND)) cs->conn->xprt->subscribe(cs->conn, SUB_CAN_SEND, &h1c->wait_event); } - - return ret; + return total; } #if defined(CONFIG_HAP_LINUX_SPLICE)