]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h2: add the function to create a new stream
authorWilly Tarreau <w@1wt.eu>
Fri, 13 Oct 2017 17:07:26 +0000 (19:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 17:16:17 +0000 (18:16 +0100)
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.

src/mux_h2.c

index 34b39fbf8297f4844a72d406d3160f9c7c0e3547..2d6d1b98594245d3552d72cf90567f1588a68c6b 100644 (file)
@@ -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 @@ static inline int h2_get_frame_hdr(struct buffer *b, struct h2_fh *h)
        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 */