]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h2: make each H2 stream support an intermediary input buffer
authorWilly Tarreau <w@1wt.eu>
Mon, 26 Feb 2018 14:22:17 +0000 (15:22 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Jul 2018 17:21:43 +0000 (19:21 +0200)
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.

src/mux_h2.c

index 41bd8ebbb765ee64ce19539eb3d2ec566c38751d..3f77157b8f8ebe3907a3c12fe06836f4d085e4de 100644 (file)
@@ -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;
 }