]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mux: make mux->snd_buf() take the byte count in argument
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Jun 2018 16:38:55 +0000 (18:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:41 +0000 (16:23 +0200)
This way the mux doesn't need to modify the buffer's metadata anymore
nor to know the output's size. The mux->snd_buf() function now takes a
const buffer and it's up to the caller to update the buffer's state.

The return type was updated to return a size_t to comply with the count
argument.

include/types/connection.h
src/checks.c
src/mux_h2.c
src/mux_pt.c
src/stream_interface.c

index 6cd8a3a2d33436838f22427e2718507162e41ea1..f9757e547303e5086110c9d7df03e29d493fa181 100644 (file)
@@ -298,7 +298,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 */
        int  (*rcv_buf)(struct conn_stream *cs, struct buffer *buf, int count); /* Called from the upper layer to get data */
-       int  (*snd_buf)(struct conn_stream *cs, struct buffer *buf, int flags); /* Called from the upper layer to send 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 */
        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 0150bbb7eeac3a396e872238d4845408dfd8900b..9cbc5de58d2e2e1581a0f9afbe359c8a914d8583 100644 (file)
@@ -746,7 +746,9 @@ static void event_srv_chk_w(struct conn_stream *cs)
                goto out_unlock;
 
        if (check->bo->o) {
-               conn->mux->snd_buf(cs, check->bo, 0);
+               b_del(check->bo, conn->mux->snd_buf(cs, check->bo, check->bo->o, 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);
                        __cs_stop_both(cs);
@@ -2669,9 +2671,14 @@ static int tcpcheck_main(struct check *check)
                    (&check->current_step->list == head ||
                     check->current_step->action != TCPCHK_ACT_SEND ||
                     check->current_step->string_len >= buffer_total_space(check->bo))) {
+                       int ret;
 
                        __cs_want_send(cs);
-                       if (conn->mux->snd_buf(cs, check->bo, 0) <= 0) {
+                       ret = conn->mux->snd_buf(cs, check->bo, check->bo->o, 0);
+                       b_del(check->bo, ret);
+                       b_realign_if_empty(check->bo);
+
+                       if (ret <= 0) {
                                if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR) {
                                        chk_report_conn_err(check, errno, 0);
                                        __cs_stop_both(cs);
index 2251a8e046f0a0cd1dc64352f5efe993bbe78d68..4a39b51044919c06cbe4c54b01a0630380daebff 100644 (file)
@@ -3378,10 +3378,9 @@ static size_t h2s_frt_make_resp_data(struct h2s *h2s, const struct buffer *buf,
 }
 
 /* Called from the upper layer, to send data */
-static int h2_snd_buf(struct conn_stream *cs, struct buffer *buf, int flags)
+static size_t h2_snd_buf(struct conn_stream *cs, const struct buffer *buf, size_t count, int flags)
 {
        struct h2s *h2s = cs->ctx;
-       size_t count = buf->o;
        size_t total = 0;
        size_t ret;
 
@@ -3452,7 +3451,6 @@ static int h2_snd_buf(struct conn_stream *cs, struct buffer *buf, int flags)
                        LIST_ADDQ(&h2s->h2c->send_list, &h2s->list);
        }
 
-       b_del(buf, total);
        return total;
 }
 
index 688b7d8faba2aa03fd5f59e842a9fbcec4db1c9f..d65c4e2024ff728d8fc7a8aac5d7a71ee9bc5e2b 100644 (file)
@@ -172,15 +172,9 @@ static int mux_pt_rcv_buf(struct conn_stream *cs, struct buffer *buf, int count)
 }
 
 /* Called from the upper layer, to send data */
-static int mux_pt_snd_buf(struct conn_stream *cs, struct buffer *buf, int flags)
+static size_t mux_pt_snd_buf(struct conn_stream *cs, const struct buffer *buf, size_t count, int flags)
 {
-       int ret = cs->conn->xprt->snd_buf(cs->conn, buf, buf->o, flags);
-
-       if (ret > 0)
-               b_del(buf, ret);
-
-       b_realign_if_empty(buf);
-       return ret;
+       return cs->conn->xprt->snd_buf(cs->conn, buf, count, flags);
 }
 
 #if defined(CONFIG_HAP_LINUX_SPLICE)
index 62cbf71f3e24ee47905704c3397c3139db0cf601..4a095d8dae6f563c2b6de1dee093afdcbf9a1b95 100644 (file)
@@ -683,11 +683,14 @@ static void si_cs_send(struct conn_stream *cs)
                if (oc->flags & CF_STREAMER)
                        send_flag |= CO_SFL_STREAMER;
 
-               ret = conn->mux->snd_buf(cs, oc->buf, send_flag);
+               ret = conn->mux->snd_buf(cs, oc->buf, co_data(oc), send_flag);
                if (ret > 0) {
                        oc->flags |= CF_WRITE_PARTIAL | CF_WROTE_DATA | CF_WRITE_EVENT;
 
-                       if (!oc->buf->o) {
+                       b_del(oc->buf, ret);
+                       c_realign_if_empty(oc);
+
+                       if (!co_data(oc)) {
                                /* Always clear both flags once everything has been sent, they're one-shot */
                                oc->flags &= ~(CF_EXPECT_MORE | CF_SEND_DONTWAIT);
                        }