From 29a22bc0a7fcc25e02b1fd173c8f0095d653d501 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Tue, 4 Dec 2018 18:16:45 +0100 Subject: [PATCH] MEDIUM: h1: Realign the ibuf before calling rcv_buf if needed. If the ibuf only contains a small amount of data, realign it before calling rcv_buf(), as it's probably going to be cheaper to do so than to do 2 calls to recv(). --- src/mux_h1.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mux_h1.c b/src/mux_h1.c index b0d556700..1c980dca6 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -1484,6 +1484,13 @@ static int h1_recv(struct h1c *h1c) goto end; } + /* + * If we only have a small amount of data, realign it, + * it's probably cheaper than doing 2 recv() calls. + */ + if (b_data(&h1c->ibuf) > 0 && b_data(&h1c->ibuf) < 128) + b_slow_realign(&h1c->ibuf, trash.area, 0); + max = b_room(&h1c->ibuf); if (max) { h1c->flags &= ~H1C_F_IN_FULL;