]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-quic: factorize conn-stream attach
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 4 Apr 2022 14:13:44 +0000 (16:13 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 7 Apr 2022 08:10:23 +0000 (10:10 +0200)
Provide a new function qc_attach_cs. This must be used by the app layer
when a conn-stream can be instantiated. This will simplify future
development.

include/haproxy/mux_quic.h
src/h3.c
src/hq_interop.c

index f0c0a430ef8eb91c3642b0a35d6fce7e391b256c..715f7e9f55065de7008161c95293595aac12c6d1 100644 (file)
@@ -11,6 +11,7 @@
 #include <haproxy/api.h>
 #include <haproxy/connection.h>
 #include <haproxy/mux_quic-t.h>
+#include <haproxy/stream.h>
 #include <haproxy/xprt_quic-t.h>
 
 struct qcs *qcs_new(struct qcc *qcc, uint64_t id, enum qcs_type type);
@@ -104,6 +105,19 @@ static inline struct qc_stream_desc *qcc_get_stream(struct qcc *qcc, uint64_t id
        return eb64_entry(node, struct qc_stream_desc, by_id);
 }
 
+static inline struct conn_stream *qc_attach_cs(struct qcs *qcs, struct buffer *buf)
+{
+       struct conn_stream *cs = cs_new();
+       if (!cs)
+               return NULL;
+       cs_attach_endp(cs, &qcs->qcc->conn->obj_type, qcs);
+
+       cs->ctx = qcs;
+       stream_new(qcs->qcc->conn->owner, cs, buf);
+
+       return cs;
+}
+
 #endif /* USE_QUIC */
 
 #endif /* _HAPROXY_MUX_QUIC_H */
index a7968454a85fb18a787427835208068d2cd0637c..3cce59563203bfaf31cd161d7e4859298baee34f 100644 (file)
--- a/src/h3.c
+++ b/src/h3.c
 #include <haproxy/http.h>
 #include <haproxy/htx.h>
 #include <haproxy/istbuf.h>
-#include <haproxy/mux_quic-t.h>
+#include <haproxy/mux_quic.h>
 #include <haproxy/pool.h>
 #include <haproxy/qpack-dec.h>
 #include <haproxy/qpack-enc.h>
 #include <haproxy/quic_enc.h>
-#include <haproxy/stream.h>
 #include <haproxy/tools.h>
 #include <haproxy/xprt_quic.h>
 
@@ -174,14 +173,10 @@ static int h3_headers_to_htx(struct qcs *qcs, struct buffer *buf, uint64_t len,
        if (fin)
                htx->flags |= HTX_FL_EOM;
 
-       cs = cs_new();
+       cs = qc_attach_cs(qcs, &htx_buf);
        if (!cs)
                return 1;
-       cs_attach_endp(cs, &qcs->qcc->conn->obj_type, qcs);
-
        cs->flags |= CS_FL_NOT_FIRST;
-       cs->ctx = qcs;
-       stream_new(qcs->qcc->conn->owner, cs, &htx_buf);
 
        /* buffer is transferred to conn_stream and set to NULL
         * except on stream creation error.
index 0e5561d8aa9792b13c3ebbeae5eda4e0fff02fd2..79283736cd1de444ac29e8c7dc6b80b959ec753d 100644 (file)
@@ -6,8 +6,7 @@
 #include <haproxy/dynbuf.h>
 #include <haproxy/htx.h>
 #include <haproxy/http.h>
-#include <haproxy/mux_quic-t.h>
-#include <haproxy/stream.h>
+#include <haproxy/mux_quic.h>
 
 static int hq_interop_decode_qcs(struct qcs *qcs, int fin, void *ctx)
 {
@@ -72,12 +71,9 @@ static int hq_interop_decode_qcs(struct qcs *qcs, int fin, void *ctx)
        htx_add_endof(htx, HTX_BLK_EOH);
        htx_to_buf(htx, &htx_buf);
 
-       cs = cs_new();
+       cs = qc_attach_cs(qcs, &htx_buf);
        if (!cs)
                return -1;
-       cs_attach_endp(cs, &qcs->qcc->conn->obj_type, qcs);
-       cs->ctx = qcs;
-       stream_new(qcs->qcc->conn->owner, cs, &htx_buf);
 
        b_del(rxbuf, b_data(rxbuf));
        b_free(&htx_buf);