From: Willy Tarreau Date: Mon, 26 Feb 2018 14:22:17 +0000 (+0100) Subject: MINOR: h2: make each H2 stream support an intermediary input buffer X-Git-Tag: v1.9-dev1~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b559071dd7c08af89fc5ebcc29a8d14e3bc470c;p=thirdparty%2Fhaproxy.git MINOR: h2: make each H2 stream support an intermediary input buffer The purpose is to decode to a temporary buffer and then to copy this buffer to the caller upon request to avoid having to process frames on the fly when called from the higher level. For now the buffer is only initialized on stream creation via cs_new() and allocated if the buffer_wait's callback is called. --- diff --git a/src/mux_h2.c b/src/mux_h2.c index 41bd8ebbb7..3f77157b8f 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -219,6 +219,7 @@ static const struct h2s *h2_idle_stream = &(const struct h2s){ static struct task *h2_timeout_task(struct task *t, void *context, unsigned short state); static struct task *h2_send(struct task *t, void *ctx, unsigned short state); +static inline struct h2s *h2c_st_by_id(struct h2c *h2c, int id); /*****************************************************/ /* functions below are for dynamic buffer management */ @@ -269,6 +270,7 @@ static inline int h2_has_too_many_cs(const struct h2c *h2c) static int h2_buf_available(void *target) { struct h2c *h2c = target; + struct h2s *h2s; if ((h2c->flags & H2_CF_DEM_DALLOC) && b_alloc_margin(&h2c->dbuf, 0)) { h2c->flags &= ~H2_CF_DEM_DALLOC; @@ -289,6 +291,16 @@ static int h2_buf_available(void *target) } return 1; } + + if ((h2c->flags & H2_CF_DEM_SALLOC) && + (h2s = h2c_st_by_id(h2c, h2c->dsi)) && h2s->cs && + b_alloc_margin(&h2s->cs->rxbuf, 0)) { + h2c->flags &= ~H2_CF_DEM_SALLOC; + if (h2_recv_allowed(h2c)) + conn_xprt_want_recv(h2c->conn); + return 1; + } + return 0; }