]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: replace b{i,o}_put* with b_put*
authorWilly Tarreau <w@1wt.eu>
Tue, 10 Jul 2018 08:04:02 +0000 (10:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:43 +0000 (16:23 +0200)
The two variants now do exactly the same (appending at the tail of the
buffer) so let's not keep the distinction between these classes of
functions and have generic ones for this. It's also worth noting that
b{i,o}_putchk() wasn't used at all and was removed.

include/common/buf.h
include/common/buffer.h
src/checks.c
src/mux_h2.c

index c38d65d85d2b1102e90a9142c91bd3f668469dcf..a7bbb1f0c157fd0884ccac4ac946b930b38dcdbe 100644 (file)
@@ -447,6 +447,53 @@ static inline void b_slow_realign(struct buffer *b, char *swap, size_t output)
        b->head = b_size(b) - output;
 }
 
+/* b_putchar() : tries to append char <c> at the end of buffer <b>. Supports
+ * wrapping. Data are truncated if buffer is full.
+ */
+static inline void b_putchr(struct buffer *b, char c)
+{
+       if (b_full(b))
+               return;
+       *b_tail(b) = c;
+       b->len++;
+}
+
+/* b_putblk() : tries to append block <blk> at the end of buffer <b>. Supports
+ * wrapping. Data are truncated if buffer is too short. It returns the number
+ * of bytes copied.
+ */
+static inline size_t b_putblk(struct buffer *b, const char *blk, size_t len)
+{
+       size_t half;
+
+       if (len > b_room(b))
+               len = b_room(b);
+       if (!len)
+               return 0;
+
+       half = b_contig_space(b);
+       if (half > len)
+               half = len;
+
+       memcpy(b_tail(b), blk, half);
+       b->len += half;
+       if (len > half) {
+               memcpy(b_tail(b), blk + half, len - half);
+               b->len += len - half;
+       }
+       return len;
+}
+
+/* b_putstr() : tries to copy string <str> into output data at buffer <b>.
+ * Supports wrapping. Data are truncated if buffer is too short. It returns the
+ * number of bytes copied.
+ */
+static inline size_t b_putstr(struct buffer *b, const char *str)
+{
+       return b_putblk(b, str, strlen(str));
+}
+
+
 #endif /* _COMMON_BUF_H */
 
 /*
index d7bfb967e49ad0643b89c75a565ff3d497a04496..d76bc012bc89585e4eb3c3992b3976d199c1ca56 100644 (file)
@@ -116,116 +116,6 @@ static inline int buffer_replace(struct buffer *b, char *pos, char *end, const c
        return buffer_replace2(b, pos, end, str, strlen(str));
 }
 
-/* Tries to append char <c> at the end of buffer <b>. Supports wrapping. Data
- * are truncated if buffer is full.
- */
-static inline void bo_putchr(struct buffer *b, char c)
-{
-       if (b_data(b) == b->size)
-               return;
-       *b_tail(b) = c;
-       b->len++;
-}
-
-/* Tries to append block <blk> at the end of buffer <b>. Supports wrapping.
- * Data are truncated if buffer is too short. It returns the number of bytes
- * copied.
- */
-static inline unsigned int bo_putblk(struct buffer *b, const char *blk, unsigned int len)
-{
-       unsigned int half;
-
-       if (len > b_room(b))
-               len = b_room(b);
-       if (!len)
-               return 0;
-
-       half = b_contig_space(b);
-       if (half > len)
-               half = len;
-
-       memcpy(b_tail(b), blk, half);
-       b->len += half;
-       if (len > half) {
-               memcpy(b_tail(b), blk + half, len - half);
-               b->len += len - half;
-       }
-       return len;
-}
-
-/* Tries to copy string <str> into output data at buffer <b>. Supports wrapping.
- * Data are truncated if buffer is too short. It returns the number of bytes
- * copied.
- */
-static inline int bo_putstr(struct buffer *b, const char *str)
-{
-       return bo_putblk(b, str, strlen(str));
-}
-
-/* Tries to copy chunk <chk> into output data at buffer <b>. Supports wrapping.
- * Data are truncated if buffer is too short. It returns the number of bytes
- * copied.
- */
-static inline int bo_putchk(struct buffer *b, const struct chunk *chk)
-{
-       return bo_putblk(b, chk->str, chk->len);
-}
-
-/* Tries to write char <c> into input data at buffer <b>. Supports wrapping.
- * Data are truncated if buffer is full.
- */
-static inline void bi_putchr(struct buffer *b, char c)
-{
-       if (b_data(b) == b->size)
-               return;
-       *b_tail(b) = c;
-       b->len++;
-}
-
-/* Tries to append block <blk> at the end of buffer <b>. Supports wrapping.
- * Data are truncated if buffer is too short. It returns the number of bytes
- * copied.
- */
-static inline unsigned int bi_putblk(struct buffer *b, const char *blk, unsigned int len)
-{
-       int half;
-
-       if (len > b_room(b))
-               len = b_room(b);
-       if (!len)
-               return 0;
-
-       half = b_contig_space(b);
-       if (half > len)
-               half = len;
-
-       memcpy(b_tail(b), blk, half);
-       b->len += half;
-       if (len > half) {
-               memcpy(b_tail(b), blk + half, len - half);
-               b->len += len - half;
-       }
-       return len;
-}
-
-/* Tries to copy string <str> into input data at buffer <b>. Supports wrapping.
- * Data are truncated if buffer is too short. It returns the number of bytes
- * copied.
- */
-static inline int bi_putstr(struct buffer *b, const char *str)
-{
-       return bi_putblk(b, str, strlen(str));
-}
-
-/* Tries to copy chunk <chk> into input data at buffer <b>. Supports wrapping.
- * Data are truncated if buffer is too short. It returns the number of bytes
- * copied.
- */
-static inline int bi_putchk(struct buffer *b, const struct chunk *chk)
-{
-       return bi_putblk(b, chk->str, chk->len);
-}
-
 /* Allocates a buffer and replaces *buf with this buffer. If no memory is
  * available, &buf_wanted is used instead. No control is made to check if *buf
  * already pointed to another buffer. The allocated buffer is returned, or
index e9b531839d0143f71e8c544e7efab54e097e2a04..d2c4035ab2927cd859d0a8f02b4bd24ba1685fed 100644 (file)
@@ -1518,7 +1518,7 @@ static int connect_conn_chk(struct task *t)
         * its own strings.
         */
        if (check->type && check->type != PR_O2_TCPCHK_CHK && !(check->state & CHK_ST_AGENT)) {
-               bo_putblk(check->bo, s->proxy->check_req, s->proxy->check_len);
+               b_putblk(check->bo, s->proxy->check_req, s->proxy->check_len);
 
                /* we want to check if this host replies to HTTP or SSLv3 requests
                 * so we'll send the request, and won't wake the checker up now.
@@ -1530,17 +1530,17 @@ static int connect_conn_chk(struct task *t)
                }
                else if ((check->type) == PR_O2_HTTP_CHK) {
                        if (s->proxy->options2 & PR_O2_CHK_SNDST)
-                               bo_putblk(check->bo, trash.str, httpchk_build_status_header(s, trash.str, trash.size));
+                               b_putblk(check->bo, trash.str, httpchk_build_status_header(s, trash.str, trash.size));
                        /* prevent HTTP keep-alive when "http-check expect" is used */
                        if (s->proxy->options2 & PR_O2_EXP_TYPE)
-                               bo_putstr(check->bo, "Connection: close\r\n");
-                       bo_putstr(check->bo, "\r\n");
+                               b_putstr(check->bo, "Connection: close\r\n");
+                       b_putstr(check->bo, "\r\n");
                        *b_tail(check->bo) = '\0'; /* to make gdb output easier to read */
                }
        }
 
        if ((check->type & PR_O2_LB_AGENT_CHK) && check->send_string_len) {
-               bo_putblk(check->bo, check->send_string, check->send_string_len);
+               b_putblk(check->bo, check->send_string, check->send_string_len);
        }
 
        /* for tcp-checks, the initial connection setup is handled separately as
@@ -2868,7 +2868,7 @@ static int tcpcheck_main(struct check *check)
                        if (check->current_step->string_len >= b_room(check->bo))
                                continue;
 
-                       bo_putblk(check->bo, check->current_step->string, check->current_step->string_len);
+                       b_putblk(check->bo, check->current_step->string, check->current_step->string_len);
                        *b_tail(check->bo) = '\0'; /* to make gdb output easier to read */
 
                        /* go to next rule and try to send */
index 46d69bb29eb4c3f926ab1ae8114ac536585af7c2..d748eaa18c281305f0f22e3a6d1bdd5d43fc09b0 100644 (file)
@@ -2838,7 +2838,7 @@ static int h2_frt_transfer_data(struct h2s *h2s, struct buffer *buf, int count,
                do {
                        *--beg = hextab[chksz & 0xF];
                } while (chksz >>= 4);
-               bi_putblk(buf, beg, str + sizeof(str) - beg);
+               b_putblk(buf, beg, str + sizeof(str) - beg);
        }
 
        /* Block1 is the length of the first block before the buffer wraps,
@@ -2850,14 +2850,14 @@ static int h2_frt_transfer_data(struct h2s *h2s, struct buffer *buf, int count,
        block2 = flen - block1;
 
        if (block1)
-               bi_putblk(buf, b_head(h2c->dbuf), block1);
+               b_putblk(buf, b_head(h2c->dbuf), block1);
 
        if (block2)
-               bi_putblk(buf, b_peek(h2c->dbuf, block1), block2);
+               b_putblk(buf, b_peek(h2c->dbuf, block1), block2);
 
        if (h2s->flags & H2_SF_DATA_CHNK) {
                /* emit the CRLF */
-               bi_putblk(buf, "\r\n", 2);
+               b_putblk(buf, "\r\n", 2);
        }
 
        /* now mark the input data as consumed (will be deleted from the buffer
@@ -2883,7 +2883,7 @@ static int h2_frt_transfer_data(struct h2s *h2s, struct buffer *buf, int count,
                if (count < 5)
                        goto more;
                chklen += 5;
-               bi_putblk(buf, "0\r\n\r\n", 5);
+               b_putblk(buf, "0\r\n\r\n", 5);
        }
 
        h2c->rcvd_c += h2c->dpl;