From: Willy Tarreau Date: Fri, 13 Oct 2017 17:07:26 +0000 (+0200) Subject: MINOR: h2: add the function to create a new stream X-Git-Tag: v1.8-rc1~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ccf4b2a2011245783b526340827075010a94daf;p=thirdparty%2Fhaproxy.git MINOR: h2: add the function to create a new stream This one will be used by the HEADERS frame handler and maybe later by the PUSH frame handler. It creates a conn_stream in the mux's connection. The create streams are inserted in the h2c's tree sorted by IDs. The caller is expected to have verified that the stream doesn't exist yet. --- diff --git a/src/mux_h2.c b/src/mux_h2.c index 34b39fbf82..2d6d1b9859 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -514,6 +515,54 @@ static inline int h2_get_frame_hdr(struct buffer *b, struct h2_fh *h) return ret; } +/* creates a new stream on the h2c connection and returns it, or NULL in + * case of memory allocation error. + */ +static struct h2s *h2c_stream_new(struct h2c *h2c, int id) +{ + struct conn_stream *cs; + struct h2s *h2s; + + h2s = pool_alloc2(pool2_h2s); + if (!h2s) + goto out; + + h2s->h2c = h2c; + h2s->mws = h2c->miw; + h2s->flags = H2_SF_NONE; + h2s->errcode = H2_ERR_NO_ERROR; + h2s->st = H2_SS_IDLE; + h1m_init(&h2s->req); + h1m_init(&h2s->res); + h2s->by_id.key = h2s->id = id; + h2c->max_id = id; + LIST_INIT(&h2s->list); + + eb32_insert(&h2c->streams_by_id, &h2s->by_id); + + cs = cs_new(h2c->conn); + if (!cs) + goto out_close; + + h2s->cs = cs; + cs->ctx = h2s; + + if (stream_create_from_cs(cs) < 0) + goto out_free_cs; + + /* OK done, the stream lives its own life now */ + return h2s; + + out_free_cs: + cs_free(cs); + out_close: + eb32_delete(&h2s->by_id); + pool_free2(pool2_h2s, h2s); + h2s = NULL; + out: + return h2s; +} + /*********************************************************/ /* functions below are I/O callbacks from the connection */