MINOR: mux-quic: refactor snd_buf
Factorize common code between h3 and hq-interop snd_buf operation. This
is inserted in MUX QUIC snd_buf own callback.
The h3/hq-interop API has been adjusted to directly receive a HTX
message instead of a plain buf. This led to extracting part of MUX QUIC
snd_buf in qmux_http module.
This should be backported up to 2.6.
diff --git a/include/haproxy/mux_quic-t.h b/include/haproxy/mux_quic-t.h
index 9602cc4..eaedce4 100644
--- a/include/haproxy/mux_quic-t.h
+++ b/include/haproxy/mux_quic-t.h
@@ -10,6 +10,7 @@
#include <haproxy/buf-t.h>
#include <haproxy/connection-t.h>
+#include <haproxy/htx-t.h>
#include <haproxy/list-t.h>
#include <haproxy/ncbuf-t.h>
#include <haproxy/quic_stream-t.h>
@@ -186,7 +187,7 @@
int (*init)(struct qcc *qcc);
int (*attach)(struct qcs *qcs, void *conn_ctx);
ssize_t (*decode_qcs)(struct qcs *qcs, struct buffer *b, int fin);
- size_t (*snd_buf)(struct qcs *qcs, struct buffer *buf, size_t count, int flags);
+ size_t (*snd_buf)(struct qcs *qcs, struct htx *htx, size_t count);
void (*detach)(struct qcs *qcs);
int (*finalize)(void *ctx);
void (*shutdown)(void *ctx); /* Close a connection. */
diff --git a/include/haproxy/qmux_http.h b/include/haproxy/qmux_http.h
index 776725d..4a77114 100644
--- a/include/haproxy/qmux_http.h
+++ b/include/haproxy/qmux_http.h
@@ -8,6 +8,8 @@
size_t qcs_http_rcv_buf(struct qcs *qcs, struct buffer *buf, size_t count,
char *fin);
+size_t qcs_http_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count,
+ char *fin);
#endif /* USE_QUIC */
diff --git a/src/h3.c b/src/h3.c
index 187c606..b8a8f36 100644
--- a/src/h3.c
+++ b/src/h3.c
@@ -937,20 +937,17 @@
}
/* Returns the total of bytes sent. */
-static int h3_resp_data_send(struct qcs *qcs, struct buffer *buf, size_t count)
+static int h3_resp_data_send(struct qcs *qcs, struct htx *htx, size_t count)
{
struct buffer outbuf;
struct buffer *res;
size_t total = 0;
- struct htx *htx;
int bsize, fsize, hsize;
struct htx_blk *blk;
enum htx_blk_type type;
TRACE_ENTER(H3_EV_TX_DATA, qcs->qcc->conn, qcs);
- htx = htx_from_buf(buf);
-
new_frame:
if (!count || htx_is_empty(htx))
goto end;
@@ -1012,10 +1009,9 @@
return total;
}
-static size_t h3_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count, int flags)
+static size_t h3_snd_buf(struct qcs *qcs, struct htx *htx, size_t count)
{
size_t total = 0;
- struct htx *htx;
enum htx_blk_type btype;
struct htx_blk *blk;
uint32_t bsize;
@@ -1024,8 +1020,6 @@
h3_debug_printf(stderr, "%s\n", __func__);
- htx = htx_from_buf(buf);
-
while (count && !htx_is_empty(htx) && !(qcs->flags & QC_SF_BLK_MROOM)) {
idx = htx_get_head(htx);
blk = htx_get_blk(htx, idx);
@@ -1048,9 +1042,8 @@
break;
case HTX_BLK_DATA:
- ret = h3_resp_data_send(qcs, buf, count);
+ ret = h3_resp_data_send(qcs, htx, count);
if (ret > 0) {
- htx = htx_from_buf(buf);
total += ret;
count -= ret;
if (ret < bsize)
@@ -1070,15 +1063,7 @@
}
}
- if ((htx->flags & HTX_FL_EOM) && htx_is_empty(htx))
- qcs->flags |= QC_SF_FIN_STREAM;
-
out:
- if (total) {
- if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND))
- tasklet_wakeup(qcs->qcc->wait_event.tasklet);
- }
-
return total;
}
diff --git a/src/hq_interop.c b/src/hq_interop.c
index a133cd5..37bb2e2 100644
--- a/src/hq_interop.c
+++ b/src/hq_interop.c
@@ -88,10 +88,9 @@
return &qcs->tx.buf;
}
-static size_t hq_interop_snd_buf(struct qcs *qcs, struct buffer *buf,
- size_t count, int flags)
+static size_t hq_interop_snd_buf(struct qcs *qcs, struct htx *htx,
+ size_t count)
{
- struct htx *htx;
enum htx_blk_type btype;
struct htx_blk *blk;
int32_t idx;
@@ -99,7 +98,6 @@
struct buffer *res, outbuf;
size_t total = 0;
- htx = htx_from_buf(buf);
res = mux_get_buf(qcs);
outbuf = b_make(b_tail(res), b_contig_space(res), 0, 0);
@@ -148,16 +146,8 @@
}
end:
- if ((htx->flags & HTX_FL_EOM) && htx_is_empty(htx))
- qcs->flags |= QC_SF_FIN_STREAM;
-
b_add(res, b_data(&outbuf));
- if (total) {
- if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND))
- tasklet_wakeup(qcs->qcc->wait_event.tasklet);
- }
-
return total;
}
diff --git a/src/mux_quic.c b/src/mux_quic.c
index ef11347..a396e34 100644
--- a/src/mux_quic.c
+++ b/src/mux_quic.c
@@ -2102,6 +2102,7 @@
{
struct qcs *qcs = __sc_mux_strm(sc);
size_t ret;
+ char fin;
TRACE_ENTER(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
@@ -2113,7 +2114,14 @@
goto end;
}
- ret = qcs->qcc->app_ops->snd_buf(qcs, buf, count, flags);
+ ret = qcs_http_snd_buf(qcs, buf, count, &fin);
+ if (fin)
+ qcs->flags |= QC_SF_FIN_STREAM;
+
+ if (ret) {
+ if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND))
+ tasklet_wakeup(qcs->qcc->wait_event.tasklet);
+ }
end:
TRACE_LEAVE(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
diff --git a/src/qmux_http.c b/src/qmux_http.c
index bf53df0..c777074 100644
--- a/src/qmux_http.c
+++ b/src/qmux_http.c
@@ -61,3 +61,29 @@
return ret;
}
+
+/* QUIC MUX snd_buf operation using HTX data. HTX data will be transferred from
+ * <buf> to <qcs> stream buffer. Input buffer is expected to be of length
+ * <count>. <fin> will be set to signal the last data to send for this stream.
+ *
+ * Return the size in bytes of transferred data.
+ */
+size_t qcs_http_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count,
+ char *fin)
+{
+ struct htx *htx;
+ size_t ret;
+
+ TRACE_ENTER(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
+
+ htx = htx_from_buf(buf);
+
+ ret = qcs->qcc->app_ops->snd_buf(qcs, htx, count);
+ *fin = (htx->flags & HTX_FL_EOM) && htx_is_empty(htx);
+
+ htx_to_buf(htx, buf);
+
+ TRACE_LEAVE(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
+
+ return ret;
+}