]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: remove bi_end()
authorWilly Tarreau <w@1wt.eu>
Thu, 7 Jun 2018 16:46:28 +0000 (18:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:40 +0000 (16:23 +0200)
It was replaced by ci_tail() when the channel is known, or b_tail() in
other cases.

include/common/buffer.h
src/buffer.c
src/cache.c
src/channel.c
src/compression.c
src/flt_http_comp.c
src/h1.c
src/mux_h2.c
src/proto_http.c
src/raw_sock.c
src/ssl_sock.c

index 9e1f25fa79c797cda3769fe9c41266a020f92130..0c8eeb019988bcfc65fdca5648a263fd80458e53 100644 (file)
@@ -105,18 +105,6 @@ static inline void bo_del(struct buffer *b, unsigned int del)
        b->o -= del;
 }
 
-/* Returns the end of the input data in a buffer (pointer to next
- * insertion point).
- */
-static inline char *bi_end(const struct buffer *b)
-{
-       char *ret = b->p + b->i;
-
-       if (ret >= b->data + b->size)
-               ret -= b->size;
-       return ret;
-}
-
 /* Returns the amount of output data that can contiguously be read at once */
 static inline int bo_contig_data(const struct buffer *b)
 {
@@ -448,7 +436,7 @@ static inline void bi_putchr(struct buffer *b, char c)
 {
        if (buffer_len(b) == b->size)
                return;
-       *bi_end(b) = c;
+       *b_tail(b) = c;
        b->i++;
 }
 
@@ -470,7 +458,7 @@ static inline int bi_putblk(struct buffer *b, const char *blk, int len)
        if (half > len)
                half = len;
 
-       memcpy(bi_end(b), blk, half);
+       memcpy(b_tail(b), blk, half);
        if (len > half)
                memcpy(b_ptr(b, b->i + half), blk + half, len - half);
        b->i += len;
index 5085e729510b4110d5cf3cf0ca3f94e30324550c..d6320c6852f6b462f6e7277fb35d5756f9b6dc31 100644 (file)
@@ -86,16 +86,16 @@ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int
 
        delta = len - (end - pos);
 
-       if (bi_end(b) + delta > b->data + b->size)
+       if (b_tail(b) + delta > b->data + b->size)
                return 0;  /* no space left */
 
        if (buffer_not_empty(b) &&
-           bi_end(b) + delta > b_head(b) &&
-           b_head(b) >= bi_end(b))
+           b_tail(b) + delta > b_head(b) &&
+           b_head(b) >= b_tail(b))
                return 0;  /* no space left before wrapping data */
 
        /* first, protect the end of the buffer */
-       memmove(end + delta, end, bi_end(b) - end);
+       memmove(end + delta, end, b_tail(b) - end);
 
        /* now, copy str over pos */
        if (len)
@@ -125,16 +125,16 @@ int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len)
 
        delta = len + 2;
 
-       if (bi_end(b) + delta >= b->data + b->size)
+       if (b_tail(b) + delta >= b->data + b->size)
                return 0;  /* no space left */
 
        if (buffer_not_empty(b) &&
-           bi_end(b) + delta > b_head(b) &&
-           b_head(b) >= bi_end(b))
+           b_tail(b) + delta > b_head(b) &&
+           b_head(b) >= b_tail(b))
                return 0;  /* no space left before wrapping data */
 
        /* first, protect the end of the buffer */
-       memmove(pos + delta, pos, bi_end(b) - pos);
+       memmove(pos + delta, pos, b_tail(b) - pos);
 
        /* now, copy str over pos */
        if (len && str) {
index 1265df325b6120a87a3709b7f6d1a40caf5cee58..f66106d2dfe1e3dddc50c6562cca58b9db4329af 100644 (file)
@@ -552,7 +552,7 @@ static void http_cache_io_handler(struct appctx *appctx)
        /* buffer are aligned there, should be fine */
        if (appctx->st0 == HTTP_CACHE_INIT) {
                int len = first->len - sizeof(struct cache_entry);
-               if ((shctx_row_data_get(shctx, first, (unsigned char *)bi_end(res->buf), sizeof(struct cache_entry), len)) != 0) {
+               if ((shctx_row_data_get(shctx, first, (unsigned char *)ci_tail(res), sizeof(struct cache_entry), len)) != 0) {
                        /* should never get there, because at the moment, a
                         * cache object can never be bigger than a buffer */
                         abort();
index 4f2346b6a7415ba88a101daef2b216c28e711002..62a860b5c9b7a339c9c532a87bdaf2a769000055 100644 (file)
@@ -117,7 +117,7 @@ int ci_putchr(struct channel *chn, char c)
        if (!channel_may_recv(chn))
                return -1;
 
-       *bi_end(chn->buf) = c;
+       *ci_tail(chn) = c;
 
        chn->buf->i++;
        chn->flags |= CF_READ_PARTIAL;
@@ -167,7 +167,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
 
        /* OK so the data fits in the buffer in one or two blocks */
        max = bi_contig_space(chn->buf);
-       memcpy(bi_end(chn->buf), blk, MIN(len, max));
+       memcpy(ci_tail(chn), blk, MIN(len, max));
        if (len > max)
                memcpy(chn->buf->data, blk + max, len - max);
 
index 7afd9088ee4fe5d9bb539451ea13b74d078ac80a..567827da2500be1a0bc8ef3167ae61e4ac088969 100644 (file)
@@ -221,7 +221,7 @@ static int identity_init(struct comp_ctx **comp_ctx, int level)
  */
 static int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out)
 {
-       char *out_data = bi_end(out);
+       char *out_data = b_tail(out);
        int out_len = out->size - buffer_len(out);
 
        if (out_len < in_len)
@@ -307,7 +307,7 @@ static int rfc195x_add_data(struct comp_ctx *comp_ctx, const char *in_data, int
                                return -1; /* no memory */
                }
                b_reset(tmpbuf);
-               memcpy(bi_end(tmpbuf), comp_ctx->direct_ptr, comp_ctx->direct_len);
+               memcpy(b_tail(tmpbuf), comp_ctx->direct_ptr, comp_ctx->direct_len);
                tmpbuf->i += comp_ctx->direct_len;
                comp_ctx->direct_ptr = NULL;
                comp_ctx->direct_len = 0;
@@ -317,7 +317,7 @@ static int rfc195x_add_data(struct comp_ctx *comp_ctx, const char *in_data, int
 
        if (comp_ctx->queued) {
                /* data already pending */
-               memcpy(bi_end(comp_ctx->queued), in_data, in_len);
+               memcpy(b_tail(comp_ctx->queued), in_data, in_len);
                comp_ctx->queued->i += in_len;
                return in_len;
        }
@@ -350,10 +350,10 @@ static int rfc195x_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out
        out_len = out->i;
 
        if (in_ptr)
-               out->i += slz_encode(strm, bi_end(out), in_ptr, in_len, !finish);
+               out->i += slz_encode(strm, b_tail(out), in_ptr, in_len, !finish);
 
        if (finish)
-               out->i += slz_finish(strm, bi_end(out));
+               out->i += slz_finish(strm, b_tail(out));
 
        out_len = out->i - out_len;
 
@@ -569,7 +569,7 @@ static int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int
 {
        int ret;
        z_stream *strm = &comp_ctx->strm;
-       char *out_data = bi_end(out);
+       char *out_data = b_tail(out);
        int out_len = out->size - buffer_len(out);
 
        if (in_len <= 0)
@@ -602,7 +602,7 @@ static int deflate_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out
 
        strm->next_in = NULL;
        strm->avail_in = 0;
-       strm->next_out = (unsigned char *)bi_end(out);
+       strm->next_out = (unsigned char *)b_tail(out);
        strm->avail_out = out->size - buffer_len(out);
 
        ret = deflate(strm, flag);
index d80dc08f4346d5d1c35bc40137981bbc64630bb3..0ccf23b12206dec51a60c25d8381c1a2316d2999 100644 (file)
@@ -207,9 +207,9 @@ comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg)
 
                c_adv(chn, *nxt);
                block = ci_contig_data(chn);
-               memcpy(bi_end(tmpbuf), ci_head(chn), block);
+               memcpy(b_tail(tmpbuf), ci_head(chn), block);
                if (len > block)
-                       memcpy(bi_end(tmpbuf)+block, buf->data, len-block);
+                       memcpy(b_tail(tmpbuf)+block, buf->data, len-block);
                c_rew(chn, *nxt);
 
                tmpbuf->i += len;
index ddc7daf15ea795c489bfc2e56a8462e61aa190c2..8b8545d4e85325f1a6ac9f21c387c384762eabd4 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -1292,7 +1292,7 @@ int http_forward_trailers(struct http_msg *msg)
        while (1) {
                const char *p1 = NULL, *p2 = NULL;
                const char *start = b_ptr(buf, msg->next + msg->sol);
-               const char *stop  = bi_end(buf);
+               const char *stop  = b_tail(buf);
                const char *ptr   = start;
                int bytes = 0;
 
index 5a7af54d55907edf02ee0399b1f9211022eb74ae..e2f96c7b8ee99a0c9769fd496c43473c4105c371 100644 (file)
@@ -2712,7 +2712,7 @@ static int h2_frt_decode_headers(struct h2s *h2s, struct buffer *buf, int count)
 
        /* OK now we have our header list in <list> */
        msgf = (h2c->dff & H2_F_DATA_END_STREAM) ? 0 : H2_MSGF_BODY;
-       outlen = h2_make_h1_request(list, bi_end(buf), try, &msgf);
+       outlen = h2_make_h1_request(list, b_tail(buf), try, &msgf);
 
        if (outlen < 0) {
                h2c_error(h2c, H2_ERR_COMPRESSION_ERROR);
index a009d949cce3fc32095db8dff886cb38a706187f..7b7f46c68f2881fd14f40629e97b1706370e1e5c 100644 (file)
@@ -1650,8 +1650,8 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
                                req->flags |= CF_WAKE_WRITE;
                                return 0;
                        }
-                       if (unlikely(bi_end(req->buf) < b_ptr(req->buf, msg->next) ||
-                                    bi_end(req->buf) > req->buf->data + req->buf->size - global.tune.maxrewrite))
+                       if (unlikely(ci_tail(req) < b_ptr(req->buf, msg->next) ||
+                                    ci_tail(req) > req->buf->data + req->buf->size - global.tune.maxrewrite))
                                channel_slow_realign(req, trash.str);
                }
 
@@ -5137,8 +5137,8 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                        return 0;
                }
 
-               if (unlikely(bi_end(rep->buf) < b_ptr(rep->buf, msg->next) ||
-                            bi_end(rep->buf) > rep->buf->data + rep->buf->size - global.tune.maxrewrite))
+               if (unlikely(ci_tail(rep) < b_ptr(rep->buf, msg->next) ||
+                            ci_tail(rep) > rep->buf->data + rep->buf->size - global.tune.maxrewrite))
                        channel_slow_realign(rep, trash.str);
 
                if (likely(msg->next < rep->buf->i))
index 0e1f971ef182ef5c91e253898ca152118ba7765f..16eb924087bc78ff46590bf7b6ee73d2c305af55 100644 (file)
@@ -297,7 +297,7 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
                if (try > count)
                        try = count;
 
-               ret = recv(conn->handle.fd, bi_end(buf), try, 0);
+               ret = recv(conn->handle.fd, b_tail(buf), try, 0);
 
                if (ret > 0) {
                        buf->i += ret;
index 60fce0d0292db30273e87c233b03cab6c167d3c6..56d2eed7fa5d88b1f86a49f3b04c291351f82ba9 100644 (file)
@@ -5376,7 +5376,7 @@ static int ssl_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
                        try = count;
                if (((conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_EARLY_DATA)) == CO_FL_EARLY_SSL_HS) &&
                    conn->tmp_early_data != -1) {
-                       *bi_end(buf) = conn->tmp_early_data;
+                       *b_tail(buf) = conn->tmp_early_data;
                        done++;
                        try--;
                        count--;
@@ -5390,7 +5390,7 @@ static int ssl_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
                        size_t read_length;
 
                        ret = SSL_read_early_data(conn->xprt_ctx,
-                           bi_end(buf), try, &read_length);
+                           b_tail(buf), try, &read_length);
                        if (ret == SSL_READ_EARLY_DATA_SUCCESS &&
                            read_length > 0)
                                conn->flags |= CO_FL_EARLY_DATA;
@@ -5411,7 +5411,7 @@ static int ssl_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
                        }
                } else
 #endif
-               ret = SSL_read(conn->xprt_ctx, bi_end(buf), try);
+               ret = SSL_read(conn->xprt_ctx, b_tail(buf), try);
 #ifdef OPENSSL_IS_BORINGSSL
                if (conn->flags & CO_FL_EARLY_SSL_HS) {
                        if (SSL_in_early_data(conn->xprt_ctx)) {