]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux_quic: refactor QMux send frames function
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Apr 2026 12:37:55 +0000 (14:37 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 24 Apr 2026 07:33:04 +0000 (09:33 +0200)
Clean up qcc_qstrm_send_frames(). The main change is that now return
value is clearly specified at the end of the function, depending if
everything was sent or not.

src/mux_quic_qstrm.c

index 9a6974a38cc30c85a2e1e0f7da20b867e47c23a0..cf56c23fae8fe18748cd3c59713319f126ce5009 100644 (file)
@@ -247,20 +247,23 @@ int qcc_qstrm_send_frames(struct qcc *qcc, struct list *frms)
        struct quic_frame *split_frm, *next_frm;
        struct buffer *buf = &qcc->tx.qstrm_buf;
        unsigned char *pos, *old, *end;
-       size_t ret;
-       /* Record size field length */
-       const int lensz = quic_int_getsize(quic_int_cap_length(b_size(buf)));
+       size_t sent;
+       int ret, lensz, enc;
 
        TRACE_ENTER(QMUX_EV_QCC_SEND, qcc->conn);
 
+       /* Record size field length */
+       lensz = quic_int_getsize(quic_int_cap_length(b_size(buf)));
+
+       /* Purge buffer first if remaining data to send. */
        if (b_data(buf)) {
-               ret = conn->xprt->snd_buf(conn, conn->xprt_ctx, buf, b_data(buf), NULL, 0, 0);
-               if (!ret) {
+               sent = conn->xprt->snd_buf(conn, conn->xprt_ctx, buf, b_data(buf), NULL, 0, 0);
+               if (!sent) {
                        TRACE_DEVEL("snd_buf interrupted", QMUX_EV_QCC_SEND, qcc->conn);
                        goto out;
                }
 
-               if (ret != b_data(buf)) {
+               if (sent != b_data(buf)) {
                        /* TODO */
                        ABORT_NOW();
                }
@@ -270,7 +273,7 @@ int qcc_qstrm_send_frames(struct qcc *qcc, struct list *frms)
  loop:
                split_frm = next_frm = NULL;
                b_reset(buf);
-               /* Reserve bytes for the record header. */
+               /* Reserve bytes for the record header. */
                old = pos = (unsigned char *)b_orig(buf) + lensz;
                end = (unsigned char *)b_wrap(buf);
 
@@ -302,22 +305,20 @@ int qcc_qstrm_send_frames(struct qcc *qcc, struct list *frms)
                BUG_ON(pos == old);
 
                /* Encode record header and save built payload. */
-               ret = b_quic_enc_int(buf, pos - old, lensz);
-               BUG_ON(!ret);
+               enc = b_quic_enc_int(buf, pos - old, lensz);
+               BUG_ON(!enc); /* Cannot fail as space already reserved earlier. */
                b_add(buf, pos - old);
 
-               ret = conn->xprt->snd_buf(conn, conn->xprt_ctx, buf, b_data(buf), NULL, 0, 0);
-               if (!ret) {
+               sent = conn->xprt->snd_buf(conn, conn->xprt_ctx, buf, b_data(buf), NULL, 0, 0);
+               if (!sent) {
                        TRACE_DEVEL("snd_buf interrupted", QMUX_EV_QCC_SEND, qcc->conn);
                        if (split_frm)
                                LIST_INSERT(frms, &split_frm->list);
                        break;
                }
 
-               if (ret != b_data(buf)) {
-                       /* TODO */
-                       ABORT_NOW();
-               }
+               /* TODO */
+               BUG_ON(sent != b_data(buf));
 
                if (frm->type >= QUIC_FT_STREAM_8 && frm->type <= QUIC_FT_STREAM_F)
                        qstrm_ctrl_send(frm->stream.stream, frm->stream.len);
@@ -332,13 +333,16 @@ int qcc_qstrm_send_frames(struct qcc *qcc, struct list *frms)
  out:
        if (conn->flags & CO_FL_ERROR) {
                /* TODO */
-               //ABORT_NOW();
        }
-       else if (!LIST_ISEMPTY(frms) && !(qcc->wait_event.events & SUB_RETRY_SEND)) {
-               conn->xprt->subscribe(conn, conn->xprt_ctx, SUB_RETRY_SEND, &qcc->wait_event);
-               return 1;
+       else if (!LIST_ISEMPTY(frms)) {
+               if (!(qcc->wait_event.events & SUB_RETRY_SEND))
+                       conn->xprt->subscribe(conn, conn->xprt_ctx, SUB_RETRY_SEND, &qcc->wait_event);
+               ret = 1;
+       }
+       else {
+               ret = 0;
        }
 
        TRACE_LEAVE(QMUX_EV_QCC_SEND, qcc->conn);
-       return 0;
+       return ret;
 }