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.
This commit is contained in:
Amaury Denoyelle 2022-09-19 17:14:27 +02:00
parent d80fbcaca2
commit 9534e59bb9
6 changed files with 44 additions and 32 deletions

View File

@ -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 @@ struct qcc_app_ops {
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. */

View File

@ -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 */

View File

@ -937,20 +937,17 @@ static int h3_resp_headers_send(struct qcs *qcs, struct htx *htx)
}
/* 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 @@ static int h3_resp_data_send(struct qcs *qcs, struct buffer *buf, size_t count)
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 @@ static size_t h3_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count, int
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 @@ static size_t h3_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count, int
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 @@ static size_t h3_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count, int
}
}
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;
}

View File

@ -88,10 +88,9 @@ static struct buffer *mux_get_buf(struct qcs *qcs)
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 @@ static size_t hq_interop_snd_buf(struct qcs *qcs, struct buffer *buf,
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 @@ static size_t hq_interop_snd_buf(struct qcs *qcs, struct buffer *buf,
}
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;
}

View File

@ -2102,6 +2102,7 @@ static size_t qc_snd_buf(struct stconn *sc, struct buffer *buf,
{
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 @@ static size_t qc_snd_buf(struct stconn *sc, struct buffer *buf,
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);

View File

@ -61,3 +61,29 @@ size_t qcs_http_rcv_buf(struct qcs *qcs, struct buffer *buf, size_t count,
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;
}