Amaury Denoyelle | d80fbca | 2022-09-19 17:02:28 +0200 | [diff] [blame] | 1 | #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 | */ |
| 14 | size_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 Denoyelle | 9534e59 | 2022-09-19 17:14:27 +0200 | [diff] [blame^] | 64 | |
| 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 | */ |
| 71 | size_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 | } |