From 337ea57cfc9008e7d6c2e57ead8bea9bdb093d49 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 19 Jun 2018 06:23:38 +0200 Subject: [PATCH] MINOR: connection: add a new receive flag : CO_RFL_BUF_WET With this flag we introduce the notion of "dry" vs "wet" buffers : some demultiplexers like the H2 mux require as much room as possible for some operations that are not retryable like decoding a headers frame. For this they need to know if the buffer is congested with data scheduled for leaving soon or not. Since the new API will not provide this information in the buffer itself, the caller must indicate it. We never need to know the amount of such data, just the fact that the buffer is not in its optimal condition to be used for receipt. This "CO_RFL_BUF_WET" flag is used to mention that such outgoing data are still pending in the buffer and that a sensitive receiver should better let it "dry" before using it. --- include/types/connection.h | 7 ++++++- src/mux_h2.c | 10 +++++----- src/stream_interface.c | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/types/connection.h b/include/types/connection.h index 13cbf7300f..624e01e513 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -243,7 +243,12 @@ enum { CO_SRC_BIND = 0x0008, /* bind to a specific source address when connecting */ }; -/* flags that can be passed to xprt->snd_buf() */ +/* flags that can be passed to xprt->rcv_buf() and mux->rcv_buf() */ +enum { + CO_RFL_BUF_WET = 0x0001, /* Buffer still has some output data present */ +}; + +/* flags that can be passed to xprt->snd_buf() and mux->snd_buf() */ enum { CO_SFL_MSG_MORE = 0x0001, /* More data to come afterwards */ CO_SFL_STREAMER = 0x0002, /* Producer is continuously streaming data */ diff --git a/src/mux_h2.c b/src/mux_h2.c index 250eae210c..207589b55b 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -2614,7 +2614,7 @@ static void h2_shutw(struct conn_stream *cs, enum cs_shw_mode mode) * proceed. Stream errors are reported in h2s->errcode and connection errors * in h2c->errcode. */ -static int h2_frt_decode_headers(struct h2s *h2s, struct buffer *buf, int count) +static int h2_frt_decode_headers(struct h2s *h2s, struct buffer *buf, int count, int flags) { struct h2c *h2c = h2s->h2c; const uint8_t *hdrs = (uint8_t *)h2c->dbuf->p; @@ -2689,7 +2689,7 @@ static int h2_frt_decode_headers(struct h2s *h2s, struct buffer *buf, int count) * always empty except maybe for trailers, so these operations almost * never happen. */ - if (unlikely(buf->o)) { + if (flags & CO_RFL_BUF_WET) { /* need to let the output buffer flush and * mark the buffer for later wake up. */ @@ -2775,7 +2775,7 @@ static int h2_frt_decode_headers(struct h2s *h2s, struct buffer *buf, int count) * frame header and ensured that the frame was complete or the buffer full. It * changes the frame state to FRAME_A once done. */ -static int h2_frt_transfer_data(struct h2s *h2s, struct buffer *buf, int count) +static int h2_frt_transfer_data(struct h2s *h2s, struct buffer *buf, int count, int flags) { struct h2c *h2c = h2s->h2c; int block1, block2; @@ -2937,11 +2937,11 @@ static size_t h2_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t coun switch (h2c->dft) { case H2_FT_HEADERS: - ret = h2_frt_decode_headers(h2s, buf, count); + ret = h2_frt_decode_headers(h2s, buf, count, flags); break; case H2_FT_DATA: - ret = h2_frt_transfer_data(h2s, buf, count); + ret = h2_frt_transfer_data(h2s, buf, count, flags); break; default: diff --git a/src/stream_interface.c b/src/stream_interface.c index 0afcb972cd..2677b2f0ce 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -1189,7 +1189,7 @@ static void si_cs_recv_cb(struct conn_stream *cs) break; } - ret = conn->mux->rcv_buf(cs, ic->buf, max, 0); + ret = conn->mux->rcv_buf(cs, ic->buf, max, co_data(ic) ? CO_RFL_BUF_WET : 0); if (cs->flags & CS_FL_RCV_MORE) si->flags |= SI_FL_WAIT_ROOM;