]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mux: Remove const on the buffer in mux->snd_buf()
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 27 Jul 2018 09:59:41 +0000 (11:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 7 Aug 2018 12:36:52 +0000 (14:36 +0200)
This is a partial revert of the commit deccd1116 ("MEDIUM: mux: make
mux->snd_buf() take the byte count in argument"). It is a requirement to do
zero-copy transfers. This will be mandatory when the TX buffer of the
conn_stream will be used.

So, now, data are consumed by mux->snd_buf() and not only sent. So it needs to
update the buffer state. On its side, the caller must be aware the buffer can be
replaced y an empty or unallocated one.

As a side effet of this change, the function co_set_data() is now only responsible
to update the channel set, by update ->output field.

include/proto/channel.h
include/types/connection.h
src/checks.c
src/mux_h2.c
src/mux_pt.c

index 5a1a36ee5fc5a8d4c1a350f8f483f2f1fdfe5ceb..bf84a16bbdc8c6d894a654cee2ed3fb52b3db80c 100644 (file)
@@ -193,7 +193,6 @@ static inline void c_realign_if_empty(struct channel *chn)
 /* Sets the amount of output for the channel */
 static inline void co_set_data(struct channel *c, size_t output)
 {
-       c->buf.data += output - c->output;
        c->output = output;
 }
 
index 3a66ed5da59071c4877b15ce8ff4d912468e4896..83c6bd182f27da284e955058305f2ccea6b35592 100644 (file)
@@ -311,7 +311,7 @@ struct mux_ops {
        int  (*wake)(struct connection *conn);        /* mux-layer callback to report activity, mandatory */
        void (*update_poll)(struct conn_stream *cs);  /* commit cs flags to mux/conn */
        size_t (*rcv_buf)(struct conn_stream *cs, struct buffer *buf, size_t count, int flags); /* Called from the upper layer to get data */
-       size_t (*snd_buf)(struct conn_stream *cs, const struct buffer *buf, size_t count, int flags); /* Called from the upper layer to send data */
+       size_t (*snd_buf)(struct conn_stream *cs, struct buffer *buf, size_t count, int flags); /* Called from the upper layer to send data */
        int  (*rcv_pipe)(struct conn_stream *cs, struct pipe *pipe, unsigned int count); /* recv-to-pipe callback */
        int  (*snd_pipe)(struct conn_stream *cs, struct pipe *pipe); /* send-to-pipe callback */
        void (*shutr)(struct conn_stream *cs, enum cs_shr_mode);     /* shutr function */
index b965ee6937142989e645e33c01bdc1c45f0f7d04..31a39392333071cdad064653bece1751f36abe08 100644 (file)
@@ -771,7 +771,7 @@ static void __event_srv_chk_w(struct conn_stream *cs)
                goto out;
 
        if (b_data(&check->bo)) {
-               b_del(&check->bo, conn->mux->snd_buf(cs, &check->bo, b_data(&check->bo), 0));
+               conn->mux->snd_buf(cs, &check->bo, b_data(&check->bo), 0);
                b_realign_if_empty(&check->bo);
                if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR) {
                        chk_report_conn_err(check, errno, 0);
@@ -2700,7 +2700,6 @@ static int tcpcheck_main(struct check *check)
 
                        __cs_want_send(cs);
                        ret = conn->mux->snd_buf(cs, &check->bo, b_data(&check->bo), 0);
-                       b_del(&check->bo, ret);
                        b_realign_if_empty(&check->bo);
 
                        if (ret <= 0) {
index 78db21e911d48141d688542eea858300a97bb3e8..f46504cab26b9ea92877a7804f40602bfb492766 100644 (file)
@@ -3415,7 +3415,7 @@ static int h2_subscribe(struct conn_stream *cs, int event_type, void *param)
 }
 
 /* Called from the upper layer, to send data */
-static size_t h2_snd_buf(struct conn_stream *cs, const struct buffer *buf, size_t count, int flags)
+static size_t h2_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
 {
        struct h2s *h2s = cs->ctx;
        size_t total = 0;
@@ -3486,6 +3486,7 @@ static size_t h2_snd_buf(struct conn_stream *cs, const struct buffer *buf, size_
                        LIST_ADDQ(&h2s->h2c->fctl_list, &h2s->list);
        }
 
+       b_del(buf, total);
        return total;
 }
 
index 7fb377955566a5e2d0a48eb53e661c6a4775bc3a..d6c1f83ab3f98b9fd70f5c8cc3a2d7df9a26e69e 100644 (file)
@@ -159,9 +159,13 @@ static size_t mux_pt_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t
 }
 
 /* Called from the upper layer, to send data */
-static size_t mux_pt_snd_buf(struct conn_stream *cs, const struct buffer *buf, size_t count, int flags)
+static size_t mux_pt_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
 {
-       return cs->conn->xprt->snd_buf(cs->conn, buf, count, flags);
+       size_t ret = cs->conn->xprt->snd_buf(cs->conn, buf, count, flags);
+
+       if (ret > 0)
+               b_del(buf, ret);
+       return ret;
 }
 
 /* Called from the upper layer, to subscribe to events */