diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:18:05 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:18:05 +0000 |
commit | b46aad6df449445a9fc4aa7b32bd40005438e3f7 (patch) | |
tree | 751aa858ca01f35de800164516b298887382919d /src/qmux_http.c | |
parent | Initial commit. (diff) | |
download | haproxy-4ab0e6324476345d1b93a1acd3eb15c0b8cfaf40.tar.xz haproxy-4ab0e6324476345d1b93a1acd3eb15c0b8cfaf40.zip |
Adding upstream version 2.9.5.upstream/2.9.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/qmux_http.c')
-rw-r--r-- | src/qmux_http.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/qmux_http.c b/src/qmux_http.c new file mode 100644 index 0000000..edf26b1 --- /dev/null +++ b/src/qmux_http.c @@ -0,0 +1,108 @@ +#include <haproxy/qmux_http.h> + +#include <haproxy/api-t.h> +#include <haproxy/htx.h> +#include <haproxy/qmux_trace.h> + +/* QUIC MUX rcv_buf operation using HTX data. Received data from stream <qcs> + * will be transferred as HTX in <buf>. Output buffer is expected to be of + * length <count>. <fin> will be set to signal the last data to receive on this + * stream. + * + * Return the size in bytes of transferred data. + */ +size_t qcs_http_rcv_buf(struct qcs *qcs, struct buffer *buf, size_t count, + char *fin) +{ + struct htx *qcs_htx = NULL; + struct htx *cs_htx = NULL; + size_t ret = 0; + + TRACE_ENTER(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs); + + *fin = 0; + qcs_htx = htx_from_buf(&qcs->rx.app_buf); + if (htx_is_empty(qcs_htx)) { + /* Set buffer data to 0 as HTX is empty. */ + htx_to_buf(qcs_htx, &qcs->rx.app_buf); + goto end; + } + + ret = qcs_htx->data; + + cs_htx = htx_from_buf(buf); + if (htx_is_empty(cs_htx) && htx_used_space(qcs_htx) <= count) { + /* EOM will be copied to cs_htx via b_xfer(). */ + if (qcs_htx->flags & HTX_FL_EOM) + *fin = 1; + + htx_to_buf(cs_htx, buf); + htx_to_buf(qcs_htx, &qcs->rx.app_buf); + b_xfer(buf, &qcs->rx.app_buf, b_data(&qcs->rx.app_buf)); + goto end; + } + + htx_xfer_blks(cs_htx, qcs_htx, count, HTX_BLK_UNUSED); + BUG_ON(qcs_htx->flags & HTX_FL_PARSING_ERROR); + + /* Copy EOM from src to dst buffer if all data copied. */ + if (htx_is_empty(qcs_htx) && (qcs_htx->flags & HTX_FL_EOM)) { + cs_htx->flags |= HTX_FL_EOM; + *fin = 1; + } + + cs_htx->extra = qcs_htx->extra ? (qcs_htx->data + qcs_htx->extra) : 0; + htx_to_buf(cs_htx, buf); + htx_to_buf(qcs_htx, &qcs->rx.app_buf); + ret -= qcs_htx->data; + + end: + TRACE_LEAVE(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs); + + 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; + int eom = 0; + + TRACE_ENTER(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs); + + htx = htxbuf(buf); + eom = (htx->flags & HTX_FL_EOM); + ret = qcs->qcc->app_ops->snd_buf(qcs, buf, count); + *fin = (eom && !b_data(buf)); + + TRACE_LEAVE(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs); + + return ret; +} + +/* QUIC MUX snd_buf reset. HTX data stored in <buf> of length <count> will be + * cleared. This can be used when data should not be transmitted any longer. + * + * Return the size in bytes of cleared data. + */ +size_t qcs_http_reset_buf(struct qcs *qcs, struct buffer *buf, size_t count) +{ + struct htx *htx; + + TRACE_ENTER(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs); + + htx = htx_from_buf(buf); + htx_reset(htx); + htx_to_buf(htx, buf); + + TRACE_LEAVE(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs); + + return count; +} |