From: Willy Tarreau Date: Fri, 22 Sep 2017 06:07:25 +0000 (+0200) Subject: MEDIUM: h2: allocate and release the h2c context on connection init/end X-Git-Tag: v1.8-rc1~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=32218eb3448e6ef31f43ea56701d55d86f26bb49;p=thirdparty%2Fhaproxy.git MEDIUM: h2: allocate and release the h2c context on connection init/end The connection's h2c context is now allocated and initialized on mux initialization, and released on mux destruction. Note that for now the release() code is never called. --- diff --git a/src/mux_h2.c b/src/mux_h2.c index 5e7df46619..fa8f24a04e 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -135,6 +135,50 @@ static int h2_settings_max_concurrent_streams = 100; /* functions below are dedicated to the mux setup and management */ /*****************************************************************/ +/* tries to initialize the inbound h2c mux. Returns < 0 in case of failure. */ +static int h2c_frt_init(struct connection *conn) +{ + struct h2c *h2c; + + h2c = pool_alloc2(pool2_h2c); + if (!h2c) + goto fail; + + h2c->ddht = hpack_dht_alloc(h2_settings_header_table_size); + if (!h2c->ddht) + goto fail; + + /* Initialise the context. */ + h2c->st0 = H2_CS_PREFACE; + h2c->conn = conn; + h2c->max_id = -1; + h2c->errcode = H2_ERR_NO_ERROR; + h2c->flags = H2_CF_NONE; + h2c->rcvd_c = 0; + h2c->rcvd_s = 0; + + h2c->dbuf = &buf_empty; + h2c->dsi = -1; + h2c->msi = -1; + h2c->last_sid = -1; + + h2c->mbuf = &buf_empty; + h2c->miw = 65535; /* mux initial window size */ + h2c->mws = 65535; /* mux window size */ + h2c->mfs = 16384; /* initial max frame size */ + h2c->streams_by_id = EB_ROOT_UNIQUE; + LIST_INIT(&h2c->send_list); + LIST_INIT(&h2c->fctl_list); + conn->mux_ctx = h2c; + + conn_xprt_want_recv(conn); + /* mux->wake will be called soon to complete the operation */ + return 0; + fail: + pool_free2(pool2_h2c, h2c); + return -1; +} + /* Initialize the mux once it's attached. For outgoing connections, the context * is already initialized before installing the mux, so we detect incoming * connections from the fact that the context is still NULL. Returns < 0 on @@ -147,8 +191,7 @@ static int h2_init(struct connection *conn) return -1; } - /* not implemented yet */ - return -1; + return h2c_frt_init(conn); } /* release function for a connection. This one should be called to free all @@ -156,6 +199,23 @@ static int h2_init(struct connection *conn) */ static void h2_release(struct connection *conn) { + struct h2c *h2c = conn->mux_ctx; + + LIST_DEL(&conn->list); + + if (h2c) { + hpack_dht_free(h2c->ddht); + pool_free2(pool2_h2c, h2c); + } + + conn->mux = NULL; + conn->mux_ctx = NULL; + + conn_stop_tracking(conn); + conn_full_close(conn); + if (conn->destroy_cb) + conn->destroy_cb(conn); + conn_free(conn); }