From: Christopher Faulet Date: Fri, 27 Jul 2018 09:59:41 +0000 (+0200) Subject: MEDIUM: mux: Remove const on the buffer in mux->snd_buf() X-Git-Tag: v1.9-dev2~195 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d44a9b36277b9777676a8d31ae2b34bf8d056297;p=thirdparty%2Fhaproxy.git MEDIUM: mux: Remove const on the buffer in mux->snd_buf() 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. --- diff --git a/include/proto/channel.h b/include/proto/channel.h index 5a1a36ee5f..bf84a16bbd 100644 --- a/include/proto/channel.h +++ b/include/proto/channel.h @@ -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; } diff --git a/include/types/connection.h b/include/types/connection.h index 3a66ed5da5..83c6bd182f 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -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 */ diff --git a/src/checks.c b/src/checks.c index b965ee6937..31a3939233 100644 --- a/src/checks.c +++ b/src/checks.c @@ -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) { diff --git a/src/mux_h2.c b/src/mux_h2.c index 78db21e911..f46504cab2 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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; } diff --git a/src/mux_pt.c b/src/mux_pt.c index 7fb3779555..d6c1f83ab3 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -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 */