blob: 3ce4a343802e368937352120437d969c02a62cff [file] [log] [blame]
Amaury Denoyelled80fbca2022-09-19 17:02:28 +02001#include <haproxy/qmux_http.h>
2
3#include <haproxy/api-t.h>
4#include <haproxy/htx.h>
5#include <haproxy/qmux_trace.h>
6
7/* QUIC MUX rcv_buf operation using HTX data. Received data from stream <qcs>
8 * will be transferred as HTX in <buf>. Output buffer is expected to be of
9 * length <count>. <fin> will be set to signal the last data to receive on this
10 * stream.
11 *
12 * Return the size in bytes of transferred data.
13 */
14size_t qcs_http_rcv_buf(struct qcs *qcs, struct buffer *buf, size_t count,
15 char *fin)
16{
17 struct htx *qcs_htx = NULL;
18 struct htx *cs_htx = NULL;
19 size_t ret = 0;
20
21 TRACE_ENTER(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
22
23 *fin = 0;
24 qcs_htx = htx_from_buf(&qcs->rx.app_buf);
25 if (htx_is_empty(qcs_htx)) {
26 /* Set buffer data to 0 as HTX is empty. */
27 htx_to_buf(qcs_htx, &qcs->rx.app_buf);
28 goto end;
29 }
30
31 ret = qcs_htx->data;
32
33 cs_htx = htx_from_buf(buf);
34 if (htx_is_empty(cs_htx) && htx_used_space(qcs_htx) <= count) {
35 /* EOM will be copied to cs_htx via b_xfer(). */
36 if (qcs_htx->flags & HTX_FL_EOM)
37 *fin = 1;
38
39 htx_to_buf(cs_htx, buf);
40 htx_to_buf(qcs_htx, &qcs->rx.app_buf);
41 b_xfer(buf, &qcs->rx.app_buf, b_data(&qcs->rx.app_buf));
42 goto end;
43 }
44
45 htx_xfer_blks(cs_htx, qcs_htx, count, HTX_BLK_UNUSED);
46 BUG_ON(qcs_htx->flags & HTX_FL_PARSING_ERROR);
47
48 /* Copy EOM from src to dst buffer if all data copied. */
49 if (htx_is_empty(qcs_htx) && (qcs_htx->flags & HTX_FL_EOM)) {
50 cs_htx->flags |= HTX_FL_EOM;
51 *fin = 1;
52 }
53
54 cs_htx->extra = qcs_htx->extra ? (qcs_htx->data + qcs_htx->extra) : 0;
55 htx_to_buf(cs_htx, buf);
56 htx_to_buf(qcs_htx, &qcs->rx.app_buf);
57 ret -= qcs_htx->data;
58
59 end:
60 TRACE_LEAVE(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
61
62 return ret;
63}
Amaury Denoyelle9534e592022-09-19 17:14:27 +020064
65/* QUIC MUX snd_buf operation using HTX data. HTX data will be transferred from
66 * <buf> to <qcs> stream buffer. Input buffer is expected to be of length
67 * <count>. <fin> will be set to signal the last data to send for this stream.
68 *
69 * Return the size in bytes of transferred data.
70 */
71size_t qcs_http_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count,
72 char *fin)
73{
74 struct htx *htx;
75 size_t ret;
76
77 TRACE_ENTER(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
78
79 htx = htx_from_buf(buf);
80
81 ret = qcs->qcc->app_ops->snd_buf(qcs, htx, count);
82 *fin = (htx->flags & HTX_FL_EOM) && htx_is_empty(htx);
83
84 htx_to_buf(htx, buf);
85
86 TRACE_LEAVE(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
87
88 return ret;
89}
Amaury Denoyelle0ed617a2022-09-20 14:46:40 +020090
91/* QUIC MUX snd_buf reset. HTX data stored in <buf> of length <count> will be
92 * cleared. This can be used when data should not be transmitted any longer.
93 *
94 * Return the size in bytes of cleared data.
95 */
96size_t qcs_http_reset_buf(struct qcs *qcs, struct buffer *buf, size_t count)
97{
98 struct htx *htx;
99
100 TRACE_ENTER(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
101
102 htx = htx_from_buf(buf);
103 htx_reset(htx);
104 htx_to_buf(htx, buf);
105
106 TRACE_LEAVE(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
107
108 return count;
109}