]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-quic: clean up qcs Tx buffer allocation API
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 13 Nov 2023 13:57:28 +0000 (14:57 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 11 Dec 2023 15:08:51 +0000 (16:08 +0100)
This function is similar to the previous one, but this time for QCS
sending buffer.

Previously, each application layer redefine their own version of
mux_get_buf() which was used to allocate <qcs.tx.buf>. Unify it under a
single function renamed qcc_get_stream_txbuf().

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

index ca5cd56e7fea941e1b74dd744aa1877cdf4f2226..b91ccdcbd01a4be86fb806a291149e44c3fa6771 100644 (file)
@@ -23,6 +23,7 @@ void qcs_notify_recv(struct qcs *qcs);
 void qcs_notify_send(struct qcs *qcs);
 
 struct buffer *qcc_get_stream_rxbuf(struct qcs *qcs);
+struct buffer *qcc_get_stream_txbuf(struct qcs *qcs);
 void qcc_reset_stream(struct qcs *qcs, int err);
 void qcc_send_stream(struct qcs *qcs, int urg);
 void qcc_abort_stream_read(struct qcs *qcs);
index d7bf1101053ff5d75a306a02a713f100259de241..ba488f26f7c3743c2210e1ae879b8fc59c865f0a 100644 (file)
--- a/src/h3.c
+++ b/src/h3.c
@@ -1415,17 +1415,6 @@ static ssize_t h3_decode_qcs(struct qcs *qcs, struct buffer *b, int fin)
        return -1;
 }
 
-/* Returns buffer for data sending.
- * May be NULL if the allocation failed.
- */
-static struct buffer *mux_get_buf(struct qcs *qcs)
-{
-       if (!b_size(&qcs->tx.buf))
-               b_alloc(&qcs->tx.buf);
-
-       return &qcs->tx.buf;
-}
-
 /* Function used to emit stream data from <qcs> control uni-stream */
 static int h3_control_send(struct qcs *qcs, void *ctx)
 {
@@ -1464,7 +1453,7 @@ static int h3_control_send(struct qcs *qcs, void *ctx)
                b_quic_enc_int(&pos, h3_settings_max_field_section_size, 0);
        }
 
-       res = mux_get_buf(qcs);
+       res = qcc_get_stream_txbuf(qcs);
        if (b_room(res) < b_data(&pos)) {
                // TODO the mux should be put in blocked state, with
                // the stream in state waiting for settings to be sent
@@ -1533,7 +1522,8 @@ static int h3_resp_headers_send(struct qcs *qcs, struct htx *htx)
 
        list[hdr].n = ist("");
 
-       res = mux_get_buf(qcs);
+       if (!(res = qcc_get_stream_txbuf(qcs)))
+               goto err;
 
        /* At least 5 bytes to store frame type + length as a varint max size */
        if (b_room(res) < 5)
@@ -1663,7 +1653,8 @@ static int h3_resp_trailers_send(struct qcs *qcs, struct htx *htx)
        }
        list[hdr].n = ist("");
 
-       res = mux_get_buf(qcs);
+       if (!(res = qcc_get_stream_txbuf(qcs)))
+               goto err;
 
        /* At least 9 bytes to store frame type + length as a varint max size */
        if (b_room(res) < 9) {
@@ -1769,7 +1760,9 @@ static int h3_resp_data_send(struct qcs *qcs, struct buffer *buf, size_t count)
        if (type != HTX_BLK_DATA)
                goto end;
 
-       res = mux_get_buf(qcs);
+       if (!(res = qcc_get_stream_txbuf(qcs))) {
+               /* TODO */
+       }
 
        if (unlikely(fsize == count &&
                     !b_data(res) &&
@@ -1947,8 +1940,9 @@ static size_t h3_nego_ff(struct qcs *qcs, size_t count)
 
        h3_debug_printf(stderr, "%s\n", __func__);
 
-       /* FIXME: no check on ALLOC ? */
-       res = mux_get_buf(qcs);
+       if (!(res = qcc_get_stream_txbuf(qcs))) {
+               /* TODO */
+       }
 
        /* h3 DATA headers : 1-byte frame type + varint frame length */
        hsize = 1 + QUIC_VARINT_MAX_SIZE;
@@ -2154,7 +2148,7 @@ static int h3_send_goaway(struct h3c *h3c)
        b_quic_enc_int(&pos, frm_len, 0);
        b_quic_enc_int(&pos, h3c->id_goaway, 0);
 
-       res = mux_get_buf(qcs);
+       res = qcc_get_stream_txbuf(qcs);
        if (!res || b_room(res) < b_data(&pos)) {
                /* Do not try forcefully to emit GOAWAY if no space left. */
                TRACE_ERROR("cannot send GOAWAY", H3_EV_H3C_END, h3c->qcc->conn, qcs);
index ae4140a880a63b1878bf468449838e70de4b8099..ba2f0c7db53bf707065c420e59b601c1360abf4e 100644 (file)
@@ -83,14 +83,6 @@ static ssize_t hq_interop_decode_qcs(struct qcs *qcs, struct buffer *b, int fin)
        return b_data(b);
 }
 
-static struct buffer *mux_get_buf(struct qcs *qcs)
-{
-       if (!b_size(&qcs->tx.buf))
-               b_alloc(&qcs->tx.buf);
-
-       return &qcs->tx.buf;
-}
-
 static size_t hq_interop_snd_buf(struct qcs *qcs, struct buffer *buf,
                                  size_t count)
 {
@@ -102,7 +94,7 @@ static size_t hq_interop_snd_buf(struct qcs *qcs, struct buffer *buf,
        struct buffer *res, outbuf;
        size_t total = 0;
 
-       res = mux_get_buf(qcs);
+       res = qcc_get_stream_txbuf(qcs);
        outbuf = b_make(b_tail(res), b_contig_space(res), 0, 0);
 
        htx = htx_from_buf(buf);
@@ -163,7 +155,7 @@ static size_t hq_interop_snd_buf(struct qcs *qcs, struct buffer *buf,
 
 static size_t hq_interop_nego_ff(struct qcs *qcs, size_t count)
 {
-       struct buffer *res = mux_get_buf(qcs);
+       struct buffer *res = qcc_get_stream_txbuf(qcs);
 
        if (!b_room(res)) {
                qcs->flags |= QC_SF_BLK_MROOM;
index 4fbef0d9df78723d085167468c13c0bc4cc30211..4422e0ba157bfdf7524b21a59e4d84f42e1762fa 100644 (file)
@@ -914,6 +914,15 @@ struct buffer *qcc_get_stream_rxbuf(struct qcs *qcs)
        return b_alloc(&qcs->rx.app_buf);
 }
 
+/* Allocate if needed and retrieve <qcs> stream buffer for data emission.
+ *
+ * Returns buffer pointer. May be NULL on allocation failure.
+ */
+struct buffer *qcc_get_stream_txbuf(struct qcs *qcs)
+{
+       return b_alloc(&qcs->tx.buf);
+}
+
 /* Prepare for the emission of RESET_STREAM on <qcs> with error code <err>. */
 void qcc_reset_stream(struct qcs *qcs, int err)
 {