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 34b39fb..2d6d1b9 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -17,6 +17,7 @@
#include <common/net_helper.h>
#include <proto/applet.h>
#include <proto/connection.h>
+#include <proto/h1.h>
#include <proto/stream.h>
#include <eb32tree.h>
@@ -514,6 +515,54 @@
return ret;
}
+/* creates a new stream <id> 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 */