]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mux-h2: make h2_rcv_buf() support HTX transfers
authorWilly Tarreau <w@1wt.eu>
Sat, 1 Dec 2018 22:19:43 +0000 (23:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 1 Dec 2018 22:25:55 +0000 (23:25 +0100)
The function needs to be slightly adapted to transfer HTX blocks, since
it may face a full buffer on the receive path, thus it needs to transfer
HTX blocks between the two sides ignoring the <count> argument in this
mode.

src/mux_h2.c

index 001d1dad8fe52d3db528c9e46a703e649bdc07b3..c07cdd96212d53a3ee44372ed237a5268d3c5c6f 100644 (file)
@@ -3579,10 +3579,31 @@ static size_t h2_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t coun
 {
        struct h2s *h2s = cs->ctx;
        struct h2c *h2c = h2s->h2c;
+       struct htx *h2s_htx = NULL;
+       struct htx *buf_htx = NULL;
+       struct htx_ret htx_ret;
        size_t ret = 0;
 
        /* transfer possibly pending data to the upper layer */
-       ret = b_xfer(buf, &h2s->rxbuf, count);
+       if (h2c->proxy->options2 & PR_O2_USE_HTX) {
+               /* in HTX mode we ignore the count argument */
+               h2s_htx = htx_from_buf(&h2s->rxbuf);
+               if (htx_is_empty(h2s_htx))
+                       goto end;
+
+               buf_htx = htx_from_buf(buf);
+               count = htx_free_space(buf_htx);
+
+               htx_ret = htx_xfer_blks(buf_htx, h2s_htx, count, (h2s_htx->sl_off != -1) ? HTX_BLK_EOH : HTX_BLK_EOM);
+
+               buf_htx->extra = h2s_htx->extra;
+               if (htx_is_not_empty(buf_htx))
+                       b_set_data(buf, b_size(buf));
+               ret = htx_ret.ret;
+       }
+       else {
+               ret = b_xfer(buf, &h2s->rxbuf, count);
+       }
 
        if (b_data(&h2s->rxbuf))
                cs->flags |= CS_FL_RCV_MORE;
@@ -3604,7 +3625,7 @@ static size_t h2_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t coun
                                tasklet_wakeup(h2c->wait_event.task);
                }
        }
-
+end:
        return ret;
 }