]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: buffers: rename a number of buffer management functions
authorWilly Tarreau <w@1wt.eu>
Mon, 7 May 2012 09:56:55 +0000 (11:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 18:56:56 +0000 (20:56 +0200)
The following renaming took place :
1) buffer input functions
  buffer_put_block => bi_putblk
  buffer_put_char => bi_putchr
  buffer_put_string => bi_putstr
  buffer_put_chunk => bi_putchk
  buffer_feed => bi_putstr
  buffer_feed_chunk => bi_putchk
  buffer_cut_tail => bi_erase
  buffer_ignore => bi_fast_delete

2) buffer output functions
  buffer_get_char => bo_getchr
  buffer_get_line => bo_getline
  buffer_get_block => bo_getblk
  buffer_skip => bo_skip
  buffer_write => bo_inject

3) buffer input avail/full functions were introduced :
  bi_avail
  bi_full

include/proto/buffers.h
src/buffers.c
src/dumpstats.c
src/peers.c
src/proto_http.c
src/stream_interface.c
src/stream_sock.c

index f82e461d5eacb64c8ab70f013ca6c4f7daaa57f6..3b98f178a1d442d79ee8fa45c7ec4558f24891bf 100644 (file)
@@ -2,7 +2,7 @@
  * include/proto/buffers.h
  * Buffer management definitions, macros and inline functions.
  *
- * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
+ * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -40,11 +40,11 @@ extern struct pool_head *pool2_buffer;
 int init_buffer();
 
 /* SI-to-buffer functions : buffer_{get,put}_{char,block,string,chunk} */
-int buffer_write(struct buffer *buf, const char *msg, int len);
-int buffer_put_block(struct buffer *buf, const char *str, int len);
-int buffer_put_char(struct buffer *buf, char c);
-int buffer_get_line(struct buffer *buf, char *str, int len);
-int buffer_get_block(struct buffer *buf, char *blk, int len, int offset);
+int bo_inject(struct buffer *buf, const char *msg, int len);
+int bi_putblk(struct buffer *buf, const char *str, int len);
+int bi_putchr(struct buffer *buf, char c);
+int bo_getline(struct buffer *buf, char *str, int len);
+int bo_getblk(struct buffer *buf, char *blk, int len, int offset);
 int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int len);
 int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len);
 void buffer_dump(FILE *o, struct buffer *b, int from, int to);
@@ -197,22 +197,68 @@ static inline int buffer_max_len(const struct buffer *buf)
        return buf->size - buffer_reserved(buf);
 }
 
-/* Return the maximum amount of bytes that can be written into the buffer,
- * including reserved space which may be overwritten.
+/* Returns non-zero if the buffer input is considered full. The reserved space
+ * is taken into account if ->to_forward indicates that an end of transfer is
+ * close to happen. The test is optimized to avoid as many operations as
+ * possible for the fast case and to be used as an "if" condition.
  */
-static inline int buffer_total_space(const struct buffer *buf)
+static inline int bi_full(const struct buffer *b)
 {
-       return buf->size - buffer_len(buf);
+       int rem = b->size;
+
+       rem -= b->o;
+       rem -= b->i;
+       if (!rem)
+               return 1; /* buffer already full */
+
+       if (b->to_forward >= b->size ||
+           (BUF_INFINITE_FORWARD < MAX_RANGE(typeof(b->size)) && // just there to ensure gcc
+            b->to_forward == BUF_INFINITE_FORWARD))              // avoids the useless second
+               return 0;                                         // test whenever possible
+
+       rem -= global.tune.maxrewrite;
+       rem += b->o;
+       rem += b->to_forward;
+       return rem <= 0;
+}
+
+/* Returns the amount of space available at the input of the buffer, taking the
+ * reserved space into account if ->to_forward indicates that an end of transfer
+ * is close to happen. The test is optimized to avoid as many operations as
+ * possible for the fast case.
+ */
+static inline int bi_avail(const struct buffer *b)
+{
+       int rem = b->size;
+       int rem2;
+
+       rem -= b->o;
+       rem -= b->i;
+       if (!rem)
+               return rem; /* buffer already full */
+
+       if (b->to_forward >= b->size ||
+           (BUF_INFINITE_FORWARD < MAX_RANGE(typeof(b->size)) && // just there to ensure gcc
+            b->to_forward == BUF_INFINITE_FORWARD))              // avoids the useless second
+               return rem;                                         // test whenever possible
+
+       rem2 = rem - global.tune.maxrewrite;
+       rem2 += b->o;
+       rem2 += b->to_forward;
+
+       if (rem > rem2)
+               rem = rem2;
+       if (rem > 0)
+               return rem;
+       return 0;
 }
 
 /* Return the maximum amount of bytes that can be written into the buffer,
- * excluding the reserved space, which is preserved. 0 may be returned if
- * the reserved space was already reached or used.
+ * including reserved space which may be overwritten.
  */
-static inline int buffer_total_space_res(const struct buffer *buf)
+static inline int buffer_total_space(const struct buffer *buf)
 {
-       int len = buffer_max_len(buf) - buffer_len(buf);
-       return len < 0 ? 0 : len;
+       return buf->size - buffer_len(buf);
 }
 
 /* Returns the number of contiguous bytes between <start> and <start>+<count>,
@@ -410,7 +456,7 @@ static inline void buffer_erase(struct buffer *buf)
  * stopped. This is mainly to be used to send error messages after existing
  * data.
  */
-static inline void buffer_cut_tail(struct buffer *buf)
+static inline void bi_erase(struct buffer *buf)
 {
        if (!buf->o)
                return buffer_erase(buf);
@@ -421,7 +467,7 @@ static inline void buffer_cut_tail(struct buffer *buf)
 
        buf->i = 0;
        buf->flags &= ~BF_FULL;
-       if (buffer_len(buf) >= buffer_max_len(buf))
+       if (bi_full(buf))
                buf->flags |= BF_FULL;
 }
 
@@ -431,7 +477,7 @@ static inline void buffer_cut_tail(struct buffer *buf)
  * This is mainly used to remove empty lines at the beginning of a request
  * or a response.
  */
-static inline void buffer_ignore(struct buffer *buf, int n)
+static inline void bi_fast_delete(struct buffer *buf, int n)
 {
        buf->i -= n;
        buf->p += n;
@@ -533,38 +579,22 @@ static inline int buffer_realign(struct buffer *buf)
  * with <len> causing a wrapping at the end of the buffer. It's the caller's
  * responsibility to ensure that <len> is never larger than buf->o.
  */
-static inline void buffer_skip(struct buffer *buf, int len)
+static inline void bo_skip(struct buffer *buf, int len)
 {
        buf->o -= len;
+       if (!buf->o && !buf->pipe)
+               buf->flags |= BF_OUT_EMPTY;
+
        if (buffer_len(buf) == 0)
                buf->p = buf->data;
 
-       if (buffer_len(buf) < buffer_max_len(buf))
+       if (!bi_full(buf))
                buf->flags &= ~BF_FULL;
 
-       if (!buf->o && !buf->pipe)
-               buf->flags |= BF_OUT_EMPTY;
-
        /* notify that some data was written to the SI from the buffer */
        buf->flags |= BF_WRITE_PARTIAL;
 }
 
-/* writes the chunk <chunk> to buffer <buf>. Returns -1 in case of success,
- * -2 if it is larger than the buffer size, or the number of bytes available
- * otherwise. If the chunk has been written, its size is automatically reset
- * to zero. The send limit is automatically adjusted with the amount of data
- * written.
- */
-static inline int buffer_write_chunk(struct buffer *buf, struct chunk *chunk)
-{
-       int ret;
-
-       ret = buffer_write(buf, chunk->str, chunk->len);
-       if (ret == -1)
-               chunk->len = 0;
-       return ret;
-}
-
 /* Tries to copy chunk <chunk> into buffer <buf> after length controls.
  * The ->o and to_forward pointers are updated. If the buffer's input is
  * closed, -2 is returned. If the block is too large for this buffer, -3 is
@@ -573,11 +603,11 @@ static inline int buffer_write_chunk(struct buffer *buf, struct chunk *chunk)
  * Buffer flags FULL, EMPTY and READ_PARTIAL are updated if some data can be
  * transferred. The chunk's length is updated with the number of bytes sent.
  */
-static inline int buffer_put_chunk(struct buffer *buf, struct chunk *chunk)
+static inline int bi_putchk(struct buffer *buf, struct chunk *chunk)
 {
        int ret;
 
-       ret = buffer_put_block(buf, chunk->str, chunk->len);
+       ret = bi_putblk(buf, chunk->str, chunk->len);
        if (ret > 0)
                chunk->len -= ret;
        return ret;
@@ -591,18 +621,18 @@ static inline int buffer_put_chunk(struct buffer *buf, struct chunk *chunk)
  * Buffer flags FULL, EMPTY and READ_PARTIAL are updated if some data can be
  * transferred.
  */
-static inline int buffer_put_string(struct buffer *buf, const char *str)
+static inline int bi_putstr(struct buffer *buf, const char *str)
 {
-       return buffer_put_block(buf, str, strlen(str));
+       return bi_putblk(buf, str, strlen(str));
 }
 
 /*
  * Return one char from the buffer. If the buffer is empty and closed, return -2.
  * If the buffer is just empty, return -1. The buffer's pointer is not advanced,
- * it's up to the caller to call buffer_skip(buf, 1) when it has consumed the char.
+ * it's up to the caller to call bo_skip(buf, 1) when it has consumed the char.
  * Also note that this function respects the ->o limit.
  */
-static inline int buffer_get_char(struct buffer *buf)
+static inline int bo_getchr(struct buffer *buf)
 {
        /* closed or empty + imminent close = -2; empty = -1 */
        if (unlikely(buf->flags & (BF_OUT_EMPTY|BF_SHUTW))) {
@@ -613,38 +643,6 @@ static inline int buffer_get_char(struct buffer *buf)
        return *buffer_wrap_sub(buf, buf->p - buf->o);
 }
 
-
-/* DEPRECATED, just provided for compatibility, use buffer_put_chunk() instead !!!
- * returns >= 0 if the buffer is too small to hold the message, -1 if the
- * transfer was OK, -2 in case of failure.
- */
-static inline int buffer_feed_chunk(struct buffer *buf, struct chunk *msg)
-{
-       int ret = buffer_put_chunk(buf, msg);
-       if (ret >= 0) /* transfer OK */
-               return -1;
-       if (ret == -1) /* missing room */
-               return 1;
-       /* failure */
-       return -2;
-}
-
-/* DEPRECATED, just provided for compatibility, use buffer_put_string() instead !!!
- * returns >= 0 if the buffer is too small to hold the message, -1 if the
- * transfer was OK, -2 in case of failure.
- */
-static inline int buffer_feed(struct buffer *buf, const char *str)
-{
-       int ret = buffer_put_string(buf, str);
-       if (ret >= 0) /* transfer OK */
-               return -1;
-       if (ret == -1) /* missing room */
-               return 1;
-       /* failure */
-       return -2;
-}
-
-
 /* This function writes the string <str> at position <pos> which must be in
  * buffer <b>, and moves <end> just after the end of <str>. <b>'s parameters
  * (l, r, lr) are updated to be valid after the shift. the shift value
index 2bd24a8c549b888dbcf7f6b4e1f9d67425c3be16..e71f8522cd495e9246be25ad50b914b805e78922 100644 (file)
@@ -96,7 +96,7 @@ unsigned long long buffer_forward(struct buffer *buf, unsigned long long bytes)
  * Note: this function appends data to the buffer's output and possibly overwrites
  * any pending input data which are assumed not to exist.
  */
-int buffer_write(struct buffer *buf, const char *msg, int len)
+int bo_inject(struct buffer *buf, const char *msg, int len)
 {
        int max;
 
@@ -123,7 +123,7 @@ int buffer_write(struct buffer *buf, const char *msg, int len)
        buf->total += len;
 
        buf->flags &= ~(BF_OUT_EMPTY|BF_FULL);
-       if (buffer_len(buf) >= buffer_max_len(buf))
+       if (bi_full(buf))
                buf->flags |= BF_FULL;
 
        return -1;
@@ -136,7 +136,7 @@ int buffer_write(struct buffer *buf, const char *msg, int len)
  * flags FULL, EMPTY and READ_PARTIAL are updated if some data can be
  * transferred.
  */
-int buffer_put_char(struct buffer *buf, char c)
+int bi_putchr(struct buffer *buf, char c)
 {
        if (unlikely(buffer_input_closed(buf)))
                return -2;
@@ -147,7 +147,7 @@ int buffer_put_char(struct buffer *buf, char c)
        *bi_end(buf) = c;
 
        buf->i++;
-       if (buffer_len(buf) >= buffer_max_len(buf))
+       if (bi_full(buf))
                buf->flags |= BF_FULL;
        buf->flags |= BF_READ_PARTIAL;
 
@@ -171,7 +171,7 @@ int buffer_put_char(struct buffer *buf, char c)
  * Buffer flags FULL, EMPTY and READ_PARTIAL are updated if some data can be
  * transferred.
  */
-int buffer_put_block(struct buffer *buf, const char *blk, int len)
+int bi_putblk(struct buffer *buf, const char *blk, int len)
 {
        int max;
 
@@ -212,7 +212,7 @@ int buffer_put_block(struct buffer *buf, const char *blk, int len)
        }
 
        buf->flags &= ~BF_FULL;
-       if (buffer_len(buf) >= buffer_max_len(buf))
+       if (bi_full(buf))
                buf->flags |= BF_FULL;
 
        /* notify that some data was read from the SI into the buffer */
@@ -225,12 +225,12 @@ int buffer_put_block(struct buffer *buf, const char *blk, int len)
  *   >0 : number of bytes read. Includes the \n if present before len or end.
  *   =0 : no '\n' before end found. <str> is left undefined.
  *   <0 : no more bytes readable because output is shut.
- * The buffer status is not changed. The caller must call buffer_skip() to
+ * The buffer status is not changed. The caller must call bo_skip() to
  * update it. The '\n' is waited for as long as neither the buffer nor the
  * output are full. If either of them is full, the string may be returned
  * as is, without the '\n'.
  */
-int buffer_get_line(struct buffer *buf, char *str, int len)
+int bo_getline(struct buffer *buf, char *str, int len)
 {
        int ret, max;
        char *p;
@@ -275,10 +275,10 @@ int buffer_get_line(struct buffer *buf, char *str, int len)
  *   >0 : number of bytes read, equal to requested size.
  *   =0 : not enough data available. <blk> is left undefined.
  *   <0 : no more bytes readable because output is shut.
- * The buffer status is not changed. The caller must call buffer_skip() to
+ * The buffer status is not changed. The caller must call bo_skip() to
  * update it.
  */
-int buffer_get_block(struct buffer *buf, char *blk, int len, int offset)
+int bo_getblk(struct buffer *buf, char *blk, int len, int offset)
 {
        int firstblock;
 
@@ -343,7 +343,7 @@ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int
        b->flags &= ~BF_FULL;
        if (buffer_len(b) == 0)
                b->p = b->data;
-       if (buffer_len(b) >= buffer_max_len(b))
+       if (bi_full(b))
                b->flags |= BF_FULL;
 
        return delta;
@@ -381,7 +381,7 @@ int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len)
        b->i += delta;
 
        b->flags &= ~BF_FULL;
-       if (buffer_len(b) >= buffer_max_len(b))
+       if (bi_full(b))
                b->flags |= BF_FULL;
 
        return delta;
index 106ea8cb5573047967e54487d86b852b297a1c37..cddbc3ed7b8a17374c4de016dad87059467c287b 100644 (file)
@@ -428,7 +428,7 @@ static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_inte
        if (target && s->listener->perm.ux.level < ACCESS_LVL_OPER)
                chunk_printf(msg, "# contents not dumped due to insufficient privileges\n");
 
-       if (buffer_feed_chunk(si->ib, msg) >= 0)
+       if (bi_putchk(si->ib, msg) == -1)
                return 0;
 
        return 1;
@@ -499,7 +499,7 @@ static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_int
        }
        chunk_printf(msg, "\n");
 
-       if (buffer_feed_chunk(si->ib, msg) >= 0)
+       if (bi_putchk(si->ib, msg) == -1)
                return 0;
 
        return 1;
@@ -924,7 +924,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
 
                        /* return server's effective weight at the moment */
                        snprintf(trash, sizeof(trash), "%d (initial %d)\n", sv->uweight, sv->iweight);
-                       buffer_feed(si->ib, trash);
+                       bi_putstr(si->ib, trash);
                        return 1;
                }
                else { /* not "get weight" */
@@ -1386,7 +1386,7 @@ static void cli_io_handler(struct stream_interface *si)
                        if (buffer_almost_full(si->ib))
                                break;
 
-                       reql = buffer_get_line(si->ob, trash, sizeof(trash));
+                       reql = bo_getline(si->ob, trash, sizeof(trash));
                        if (reql <= 0) { /* closed or EOL not found */
                                if (reql == 0)
                                        break;
@@ -1446,7 +1446,7 @@ static void cli_io_handler(struct stream_interface *si)
                        }
 
                        /* re-adjust req buffer */
-                       buffer_skip(si->ob, reql);
+                       bo_skip(si->ob, reql);
                        req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
                }
                else {  /* output functions: first check if the output buffer is closed then abort */
@@ -1457,7 +1457,7 @@ static void cli_io_handler(struct stream_interface *si)
 
                        switch (si->applet.st0) {
                        case STAT_CLI_PRINT:
-                               if (buffer_feed(si->ib, si->applet.ctx.cli.msg) < 0)
+                               if (bi_putstr(si->ib, si->applet.ctx.cli.msg) != -1)
                                        si->applet.st0 = STAT_CLI_PROMPT;
                                break;
                        case STAT_CLI_O_INFO:
@@ -1487,7 +1487,7 @@ static void cli_io_handler(struct stream_interface *si)
 
                        /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
                        if (si->applet.st0 == STAT_CLI_PROMPT) {
-                               if (buffer_feed(si->ib, si->applet.st1 ? "\n> " : "\n") < 0)
+                               if (bi_putstr(si->ib, si->applet.st1 ? "\n> " : "\n") != -1)
                                        si->applet.st0 = STAT_CLI_GETREQ;
                        }
 
@@ -1573,7 +1573,7 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si)
        case STAT_ST_HEAD:
                if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) {
                        print_csv_header(&msg);
-                       if (buffer_feed_chunk(si->ib, &msg) >= 0)
+                       if (bi_putchk(si->ib, &msg) == -1)
                                return 0;
                }
 
@@ -1623,7 +1623,7 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si)
                                     nb_tasks_cur, run_queue_cur, idle_pct,
                                     global.node, global.desc?global.desc:""
                                     );
-                       if (buffer_feed_chunk(si->ib, &msg) >= 0)
+                       if (bi_putchk(si->ib, &msg) == -1)
                                return 0;
                }
 
@@ -1696,7 +1696,7 @@ static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri)
                                stat_status_codes[STAT_STATUS_UNKN]);
                chunk_printf(&msg, "\r\n\r\n");
 
-               if (buffer_feed_chunk(si->ib, &msg) >= 0)
+               if (bi_putchk(si->ib, &msg) == -1)
                        return 0;
 
                s->txn.status = 303;
@@ -1800,7 +1800,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri)
                chunk_printf(&msg, "\r\n");
 
                s->txn.status = 200;
-               if (buffer_feed_chunk(rep, &msg) >= 0)
+               if (bi_putchk(rep, &msg) == -1)
                        return 0;
 
                if (!(s->flags & SN_ERR_MASK))  // this is not really an error but it is
@@ -1915,7 +1915,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri)
                } else {
                        print_csv_header(&msg);
                }
-               if (buffer_feed_chunk(rep, &msg) >= 0)
+               if (bi_putchk(rep, &msg) == -1)
                        return 0;
 
                si->applet.state = STAT_ST_INFO;
@@ -2090,7 +2090,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri)
                                chunk_printf(&msg,"<p>\n");
                        }
 
-                       if (buffer_feed_chunk(rep, &msg) >= 0)
+                       if (bi_putchk(rep, &msg) == -1)
                                return 0;
                }
 
@@ -2121,7 +2121,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri)
        case STAT_ST_END:
                if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
                        chunk_printf(&msg, "</body></html>\n");
-                       if (buffer_feed_chunk(rep, &msg) >= 0)
+                       if (bi_putchk(rep, &msg) == -1)
                                return 0;
                }
 
@@ -2250,7 +2250,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                     "<th>Thrtle</th>\n"
                                     "</tr>");
 
-                       if (buffer_feed_chunk(rep, &msg) >= 0)
+                       if (bi_putchk(rep, &msg) == -1)
                                return 0;
                }
 
@@ -2407,7 +2407,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                chunk_printf(&msg, "\n");
                        }
 
-                       if (buffer_feed_chunk(rep, &msg) >= 0)
+                       if (bi_putchk(rep, &msg) == -1)
                                return 0;
                }
 
@@ -2543,7 +2543,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                     relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
                        }
 
-                       if (buffer_feed_chunk(rep, &msg) >= 0)
+                       if (bi_putchk(rep, &msg) == -1)
                                return 0;
                }
 
@@ -2953,7 +2953,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                /* finish with EOL */
                                chunk_printf(&msg, "\n");
                        }
-                       if (buffer_feed_chunk(rep, &msg) >= 0)
+                       if (bi_putchk(rep, &msg) == -1)
                                return 0;
                } /* for sv */
 
@@ -3148,7 +3148,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                chunk_printf(&msg, "\n");
 
                        }
-                       if (buffer_feed_chunk(rep, &msg) >= 0)
+                       if (bi_putchk(rep, &msg) == -1)
                                return 0;
                }
 
@@ -3176,7 +3176,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
 
                        chunk_printf(&msg, "<p>\n");
 
-                       if (buffer_feed_chunk(rep, &msg) >= 0)
+                       if (bi_putchk(rep, &msg) == -1)
                                return 0;
                }
 
@@ -3212,7 +3212,7 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
        if (si->applet.ctx.sess.section > 0 && si->applet.ctx.sess.uid != sess->uniq_id) {
                /* session changed, no need to go any further */
                chunk_printf(&msg, "  *** session terminated while we were watching it ***\n");
-               if (buffer_feed_chunk(si->ib, &msg) >= 0)
+               if (bi_putchk(si->ib, &msg) == -1)
                        return 0;
                si->applet.ctx.sess.target = NULL;
                si->applet.ctx.sess.uid = 0;
@@ -3427,7 +3427,7 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
                             sess->txn.rsp.next,
                             sess->rep->total);
 
-               if (buffer_feed_chunk(si->ib, &msg) >= 0)
+               if (bi_putchk(si->ib, &msg) == -1)
                        return 0;
 
                /* use other states to dump the contents */
@@ -3611,7 +3611,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si)
 
                        chunk_printf(&msg, "\n");
 
-                       if (buffer_feed_chunk(si->ib, &msg) >= 0) {
+                       if (bi_putchk(si->ib, &msg) == -1) {
                                /* let's try again later from this session. We add ourselves into
                                 * this session's users so that it can remove us upon termination.
                                 */
@@ -3630,7 +3630,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si)
                        else
                                chunk_printf(&msg, "Session not found.\n");
 
-                       if (buffer_feed_chunk(si->ib, &msg) >= 0)
+                       if (bi_putchk(si->ib, &msg) == -1)
                                return 0;
 
                        si->applet.ctx.sess.target = NULL;
@@ -3890,7 +3890,7 @@ static int stats_dump_errors_to_buffer(struct stream_interface *si)
                             tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
                             error_snapshot_id);
 
-               if (buffer_feed_chunk(si->ib, &msg) >= 0) {
+               if (bi_putchk(si->ib, &msg) == -1) {
                        /* Socket buffer full. Let's try again later from the same point */
                        return 0;
                }
@@ -3962,7 +3962,7 @@ static int stats_dump_errors_to_buffer(struct stream_interface *si)
                                break;
                        }
 
-                       if (buffer_feed_chunk(si->ib, &msg) >= 0) {
+                       if (bi_putchk(si->ib, &msg) == -1) {
                                /* Socket buffer full. Let's try again later from the same point */
                                return 0;
                        }
@@ -3974,7 +3974,7 @@ static int stats_dump_errors_to_buffer(struct stream_interface *si)
                        /* the snapshot changed while we were dumping it */
                        chunk_printf(&msg,
                                     "  WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
-                       if (buffer_feed_chunk(si->ib, &msg) >= 0)
+                       if (bi_putchk(si->ib, &msg) == -1)
                                return 0;
                        goto next;
                }
@@ -3989,7 +3989,7 @@ static int stats_dump_errors_to_buffer(struct stream_interface *si)
                        if (newptr == si->applet.ctx.errors.ptr)
                                return 0;
 
-                       if (buffer_feed_chunk(si->ib, &msg) >= 0) {
+                       if (bi_putchk(si->ib, &msg) == -1) {
                                /* Socket buffer full. Let's try again later from the same point */
                                return 0;
                        }
index 6c25dcd4924e693f7b7ab4027318fd375da65e03..3d2fd01d1490d5cbcb01bbc21c949d86cf676dcb 100644 (file)
@@ -232,7 +232,7 @@ switchstate:
                                si->applet.st0 = PEER_SESSION_GETVERSION;
                                /* fall through */
                        case PEER_SESSION_GETVERSION:
-                               reql = buffer_get_line(si->ob, trash, sizeof(trash));
+                               reql = bo_getline(si->ob, trash, sizeof(trash));
                                if (reql <= 0) { /* closed or EOL not found */
                                        if (reql == 0)
                                                goto out;
@@ -248,7 +248,7 @@ switchstate:
                                else
                                        trash[reql-1] = 0;
 
-                               buffer_skip(si->ob, reql);
+                               bo_skip(si->ob, reql);
 
                                /* test version */
                                if (strcmp(PEER_SESSION_PROTO_NAME " 1.0", trash) != 0) {
@@ -263,7 +263,7 @@ switchstate:
                                si->applet.st0 = PEER_SESSION_GETHOST;
                                /* fall through */
                        case PEER_SESSION_GETHOST:
-                               reql = buffer_get_line(si->ob, trash, sizeof(trash));
+                               reql = bo_getline(si->ob, trash, sizeof(trash));
                                if (reql <= 0) { /* closed or EOL not found */
                                        if (reql == 0)
                                                goto out;
@@ -279,7 +279,7 @@ switchstate:
                                else
                                        trash[reql-1] = 0;
 
-                               buffer_skip(si->ob, reql);
+                               bo_skip(si->ob, reql);
 
                                /* test hostname match */
                                if (strcmp(localpeer, trash) != 0) {
@@ -293,7 +293,7 @@ switchstate:
                        case PEER_SESSION_GETPEER: {
                                struct peer *curpeer;
                                char *p;
-                               reql = buffer_get_line(si->ob, trash, sizeof(trash));
+                               reql = bo_getline(si->ob, trash, sizeof(trash));
                                if (reql <= 0) { /* closed or EOL not found */
                                        if (reql == 0)
                                                goto out;
@@ -310,7 +310,7 @@ switchstate:
                                else
                                        trash[reql-1] = 0;
 
-                               buffer_skip(si->ob, reql);
+                               bo_skip(si->ob, reql);
 
                                /* parse line "<peer name> <pid>" */
                                p = strchr(trash, ' ');
@@ -346,7 +346,7 @@ switchstate:
                                size_t key_size;
                                char *p;
 
-                               reql = buffer_get_line(si->ob, trash, sizeof(trash));
+                               reql = bo_getline(si->ob, trash, sizeof(trash));
                                if (reql <= 0) { /* closed or EOL not found */
                                        if (reql == 0)
                                                goto out;
@@ -367,7 +367,7 @@ switchstate:
                                else
                                        trash[reql-1] = 0;
 
-                               buffer_skip(si->ob, reql);
+                               bo_skip(si->ob, reql);
 
                                /* Parse line "<table name> <type> <size>" */
                                p = strchr(trash, ' ');
@@ -448,7 +448,7 @@ switchstate:
                                struct peer_session *ps = (struct peer_session *)si->applet.private;
 
                                repl = snprintf(trash, sizeof(trash), "%d\n", PEER_SESSION_SUCCESSCODE);
-                               repl = buffer_put_block(si->ib, trash, repl);
+                               repl = bi_putblk(si->ib, trash, repl);
                                if (repl <= 0) {
                                        if (repl == -1)
                                                goto out;
@@ -512,7 +512,7 @@ switchstate:
                                        goto switchstate;
                                }
 
-                               repl = buffer_put_block(si->ib, trash, repl);
+                               repl = bi_putblk(si->ib, trash, repl);
                                if (repl <= 0) {
                                        if (repl == -1)
                                                goto out;
@@ -530,7 +530,7 @@ switchstate:
                                if (si->ib->flags & BF_WRITE_PARTIAL)
                                        ps->statuscode = PEER_SESSION_CONNECTEDCODE;
 
-                               reql = buffer_get_line(si->ob, trash, sizeof(trash));
+                               reql = bo_getline(si->ob, trash, sizeof(trash));
                                if (reql <= 0) { /* closed or EOL not found */
                                        if (reql == 0)
                                                goto out;
@@ -547,7 +547,7 @@ switchstate:
                                else
                                        trash[reql-1] = 0;
 
-                               buffer_skip(si->ob, reql);
+                               bo_skip(si->ob, reql);
 
                                /* Register status code */
                                ps->statuscode = atoi(trash);
@@ -600,7 +600,7 @@ switchstate:
                                char c;
                                int totl = 0;
 
-                               reql = buffer_get_block(si->ob, (char *)&c, sizeof(c), totl);
+                               reql = bo_getblk(si->ob, (char *)&c, sizeof(c), totl);
                                if (reql <= 0) { /* closed or EOL not found */
                                        if (reql == 0) {
                                                /* nothing to read */
@@ -625,7 +625,7 @@ switchstate:
                                                pushack = ps->pushack + (unsigned int)(c & 0x7F);
                                        }
                                        else {
-                                               reql = buffer_get_block(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
+                                               reql = bo_getblk(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
                                                if (reql <= 0) { /* closed or EOL not found */
                                                        if (reql == 0) {
                                                                goto incomplete;
@@ -642,7 +642,7 @@ switchstate:
                                                /* type string */
                                                stkey.key = stkey.data.buf;
 
-                                               reql = buffer_get_block(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
+                                               reql = bo_getblk(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
                                                if (reql <= 0) { /* closed or EOL not found */
                                                        if (reql == 0) {
                                                                goto incomplete;
@@ -653,7 +653,7 @@ switchstate:
                                                totl += reql;
                                                stkey.key_len = ntohl(netinteger);
 
-                                               reql = buffer_get_block(si->ob, stkey.key, stkey.key_len, totl);
+                                               reql = bo_getblk(si->ob, stkey.key, stkey.key_len, totl);
                                                if (reql <= 0) { /* closed or EOL not found */
                                                        if (reql == 0) {
                                                                goto incomplete;
@@ -668,7 +668,7 @@ switchstate:
                                                stkey.key_len = (size_t)-1;
                                                stkey.key = &stkey.data.integer;
 
-                                               reql = buffer_get_block(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
+                                               reql = bo_getblk(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
                                                if (reql <= 0) { /* closed or EOL not found */
                                                        if (reql == 0) {
                                                                goto incomplete;
@@ -684,7 +684,7 @@ switchstate:
                                                stkey.key_len = (size_t)-1;
                                                stkey.key = stkey.data.buf;
 
-                                               reql = buffer_get_block(si->ob, (char *)&stkey.data.buf, ps->table->table->key_size, totl);
+                                               reql = bo_getblk(si->ob, (char *)&stkey.data.buf, ps->table->table->key_size, totl);
                                                if (reql <= 0) { /* closed or EOL not found */
                                                        if (reql == 0) {
                                                                goto incomplete;
@@ -697,7 +697,7 @@ switchstate:
                                        }
 
                                        /* read server id */
-                                       reql = buffer_get_block(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
+                                       reql = bo_getblk(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
                                        if (reql <= 0) { /* closed or EOL not found */
                                                if (reql == 0) {
                                                        goto incomplete;
@@ -806,7 +806,7 @@ switchstate:
                                        /* ack message */
                                        uint32_t netinteger;
 
-                                       reql = buffer_get_block(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
+                                       reql = bo_getblk(si->ob, (char *)&netinteger, sizeof(netinteger), totl);
                                        if (reql <= 0) { /* closed or EOL not found */
                                                if (reql == 0) {
                                                        goto incomplete;
@@ -826,7 +826,7 @@ switchstate:
                                }
 
                                /* skip consumed message */
-                               buffer_skip(si->ob, totl);
+                               bo_skip(si->ob, totl);
 
                                /* loop on that state to peek next message */
                                continue;
@@ -836,7 +836,7 @@ incomplete:
                                /* Confirm finished or partial messages */
                                while (ps->confirm) {
                                        /* There is a confirm messages to send */
-                                       repl = buffer_put_char(si->ib, 'c');
+                                       repl = bi_putchr(si->ib, 'c');
                                        if (repl <= 0) {
                                                /* no more write possible */
                                                if (repl == -1)
@@ -853,7 +853,7 @@ incomplete:
                                        !(ps->table->flags & SHTABLE_F_RESYNC_PROCESS)) {
                                        /* Current peer was elected to request a resync */
 
-                                       repl = buffer_put_char(si->ib, 'R');
+                                       repl = bi_putchr(si->ib, 'R');
                                        if (repl <= 0) {
                                                /* no more write possible */
                                                if (repl == -1)
@@ -872,7 +872,7 @@ incomplete:
                                        netinteger = htonl(ps->pushack);
                                        memcpy(&trash[1], &netinteger, sizeof(netinteger));
 
-                                       repl = buffer_put_block(si->ib, trash, 1+sizeof(netinteger));
+                                       repl = bi_putblk(si->ib, trash, 1+sizeof(netinteger));
                                        if (repl <= 0) {
                                                /* no more write possible */
                                                if (repl == -1)
@@ -908,7 +908,7 @@ incomplete:
                                                        msglen = peer_prepare_datamsg(ts, ps, trash, sizeof(trash));
                                                        if (msglen) {
                                                                /* message to buffer */
-                                                               repl = buffer_put_block(si->ib, trash, msglen);
+                                                               repl = bi_putblk(si->ib, trash, msglen);
                                                                if (repl <= 0) {
                                                                        /* no more write possible */
                                                                        if (repl == -1)
@@ -942,7 +942,7 @@ incomplete:
                                                        msglen = peer_prepare_datamsg(ts, ps, trash, sizeof(trash));
                                                        if (msglen) {
                                                                /* message to buffer */
-                                                               repl = buffer_put_block(si->ib, trash, msglen);
+                                                               repl = bi_putblk(si->ib, trash, msglen);
                                                                if (repl <= 0) {
                                                                        /* no more write possible */
                                                                        if (repl == -1)
@@ -958,7 +958,7 @@ incomplete:
 
                                        if (!(ps->flags & PEER_F_TEACH_FINISHED)) {
                                                /* process final lesson message */
-                                               repl = buffer_put_char(si->ib, ((ps->table->flags & SHTABLE_RESYNC_STATEMASK) == SHTABLE_RESYNC_FINISHED) ? 'F' : 'C');
+                                               repl = bi_putchr(si->ib, ((ps->table->flags & SHTABLE_RESYNC_STATEMASK) == SHTABLE_RESYNC_FINISHED) ? 'F' : 'C');
                                                if (repl <= 0) {
                                                        /* no more write possible */
                                                        if (repl == -1)
@@ -1000,7 +1000,7 @@ incomplete:
                                                msglen = peer_prepare_datamsg(ts, ps, trash, sizeof(trash));
                                                if (msglen) {
                                                        /* message to buffer */
-                                                       repl = buffer_put_block(si->ib, trash, msglen);
+                                                       repl = bi_putblk(si->ib, trash, msglen);
                                                        if (repl <= 0) {
                                                                /* no more write possible */
                                                                if (repl == -1)
@@ -1019,7 +1019,7 @@ incomplete:
                        case PEER_SESSION_EXIT:
                                repl = snprintf(trash, sizeof(trash), "%d\n", si->applet.st1);
 
-                               if (buffer_put_block(si->ib, trash, repl) == -1)
+                               if (bi_putblk(si->ib, trash, repl) == -1)
                                        goto out;
                                si->applet.st0 = PEER_SESSION_END;
                                /* fall through */
index eac0319cf84d0c3297037a2945ab9fa8bc170b95..476b0974237486ae591fcbb46ec06307b057bfef 100644 (file)
@@ -656,7 +656,7 @@ static void http_server_error(struct session *t, struct stream_interface *si,
        buffer_auto_read(si->ib);
        if (status > 0 && msg) {
                t->txn.status = status;
-               buffer_write(si->ib, msg->str, msg->len);
+               bo_inject(si->ib, msg->str, msg->len);
        }
        if (!(t->flags & SN_ERR_MASK))
                t->flags |= err;
@@ -1308,7 +1308,7 @@ void http_msg_analyzer(struct http_msg *msg, struct hdr_idx *idx)
                                if (buf->o)
                                        goto http_msg_ood;
                                /* Remove empty leading lines, as recommended by RFC2616. */
-                               buffer_ignore(buf, ptr - beg);
+                               bi_fast_delete(buf, ptr - beg);
                        }
                        msg->sol = msg->som = ptr - buf->p;
                        hdr_idx_init(idx);
@@ -1375,7 +1375,7 @@ void http_msg_analyzer(struct http_msg *msg, struct hdr_idx *idx)
                                if (buf->o)
                                        goto http_msg_ood;
                                /* Remove empty leading lines, as recommended by RFC2616. */
-                               buffer_ignore(buf, ptr - beg);
+                               bi_fast_delete(buf, ptr - beg);
                        }
                        msg->sol = msg->som = ptr - buf->p;
                        /* we will need this when keep-alive will be supported
@@ -1998,7 +1998,7 @@ void http_message_realign(struct http_msg *msg)
        }
 
        buf->flags &= ~BF_FULL;
-       if (buffer_len(buf) >= buffer_max_len(buf))
+       if (bi_full(buf))
                buf->flags |= BF_FULL;
 }
 
@@ -2994,7 +2994,7 @@ int http_process_req_common(struct session *s, struct buffer *req, int an_bit, s
                                                /* Expect is allowed in 1.1, look for it */
                                                if (http_find_header2("Expect", 6, req->p + msg->sol, &txn->hdr_idx, &ctx) &&
                                                    unlikely(ctx.vlen == 12 && strncasecmp(ctx.line+ctx.val, "100-continue", 12) == 0)) {
-                                                       buffer_write(s->rep, http_100_chunk.str, http_100_chunk.len);
+                                                       bo_inject(s->rep, http_100_chunk.str, http_100_chunk.len);
                                                }
                                        }
                                        msg->msg_state = HTTP_MSG_100_SENT;
@@ -3154,9 +3154,9 @@ int http_process_req_common(struct session *s, struct buffer *req, int an_bit, s
                                }
                                memcpy(rdr.str + rdr.len, "\r\n\r\n", 4);
                                rdr.len += 4;
-                               buffer_write(req->prod->ob, rdr.str, rdr.len);
+                               bo_inject(req->prod->ob, rdr.str, rdr.len);
                                /* "eat" the request */
-                               buffer_ignore(req, msg->sov - msg->som);
+                               bi_fast_delete(req, msg->sov - msg->som);
                                msg->som = msg->sov;
                                req->analysers = AN_REQ_HTTP_XFER_BODY;
                                s->rep->analysers = AN_RES_HTTP_XFER_BODY;
@@ -3568,7 +3568,7 @@ int http_process_request_body(struct session *s, struct buffer *req, int an_bit)
                        /* Expect is allowed in 1.1, look for it */
                        if (http_find_header2("Expect", 6, req->p + msg->sol, &txn->hdr_idx, &ctx) &&
                            unlikely(ctx.vlen == 12 && strncasecmp(ctx.line+ctx.val, "100-continue", 12) == 0)) {
-                               buffer_write(s->rep, http_100_chunk.str, http_100_chunk.len);
+                               bo_inject(s->rep, http_100_chunk.str, http_100_chunk.len);
                        }
                }
                msg->msg_state = HTTP_MSG_100_SENT;
@@ -4067,7 +4067,7 @@ int http_sync_res_state(struct session *s)
        if (txn->rsp.msg_state == HTTP_MSG_CLOSED) {
        http_msg_closed:
                /* drop any pending data */
-               buffer_cut_tail(buf);
+               bi_erase(buf);
                buffer_auto_close(buf);
                buffer_auto_read(buf);
                goto wait_other_side;
@@ -4133,7 +4133,7 @@ int http_resync_states(struct session *s)
                buffer_abort(s->req);
                buffer_auto_close(s->req);
                buffer_auto_read(s->req);
-               buffer_cut_tail(s->req);
+               bi_erase(s->req);
        }
        else if (txn->req.msg_state == HTTP_MSG_CLOSED &&
                 txn->rsp.msg_state == HTTP_MSG_DONE &&
@@ -4542,7 +4542,7 @@ int http_wait_for_response(struct session *s, struct buffer *rep, int an_bit)
                        rep->analysers = 0;
                        txn->status = 502;
                        rep->prod->flags |= SI_FL_NOLINGER;
-                       buffer_cut_tail(rep);
+                       bi_erase(rep);
                        stream_int_retnclose(rep->cons, error_message(s, HTTP_ERR_502));
 
                        if (!(s->flags & SN_ERR_MASK))
@@ -4575,7 +4575,7 @@ int http_wait_for_response(struct session *s, struct buffer *rep, int an_bit)
                        rep->analysers = 0;
                        txn->status = 502;
                        rep->prod->flags |= SI_FL_NOLINGER;
-                       buffer_cut_tail(rep);
+                       bi_erase(rep);
                        stream_int_retnclose(rep->cons, error_message(s, HTTP_ERR_502));
 
                        if (!(s->flags & SN_ERR_MASK))
@@ -4600,7 +4600,7 @@ int http_wait_for_response(struct session *s, struct buffer *rep, int an_bit)
                        rep->analysers = 0;
                        txn->status = 504;
                        rep->prod->flags |= SI_FL_NOLINGER;
-                       buffer_cut_tail(rep);
+                       bi_erase(rep);
                        stream_int_retnclose(rep->cons, error_message(s, HTTP_ERR_504));
 
                        if (!(s->flags & SN_ERR_MASK))
@@ -4625,7 +4625,7 @@ int http_wait_for_response(struct session *s, struct buffer *rep, int an_bit)
                        rep->analysers = 0;
                        txn->status = 502;
                        rep->prod->flags |= SI_FL_NOLINGER;
-                       buffer_cut_tail(rep);
+                       bi_erase(rep);
                        stream_int_retnclose(rep->cons, error_message(s, HTTP_ERR_502));
 
                        if (!(s->flags & SN_ERR_MASK))
@@ -4975,7 +4975,7 @@ int http_process_res_common(struct session *t, struct buffer *rep, int an_bit, s
                                        rep->analysers = 0;
                                        txn->status = 502;
                                        rep->prod->flags |= SI_FL_NOLINGER;
-                                       buffer_cut_tail(rep);
+                                       bi_erase(rep);
                                        stream_int_retnclose(rep->cons, error_message(t, HTTP_ERR_502));
                                        if (!(t->flags & SN_ERR_MASK))
                                                t->flags |= SN_ERR_PRXCOND;
index b8a6d580efd00deee6eab0d2244693ef1a411c18..cea1a19b50cb392b7733e3d3d21dc31bfb40fc61 100644 (file)
@@ -74,9 +74,9 @@ void stream_int_retnclose(struct stream_interface *si, const struct chunk *msg)
        buffer_auto_close(si->ib);
        buffer_erase(si->ib);
 
-       buffer_cut_tail(si->ob);
+       bi_erase(si->ob);
        if (likely(msg && msg->len))
-               buffer_write(si->ob, msg->str, msg->len);
+               bo_inject(si->ob, msg->str, msg->len);
 
        si->ob->wex = tick_add_ifset(now_ms, si->ob->wto);
        buffer_auto_read(si->ob);
index 575e24c0bdc664637fcbba7473d749fb47b1b781..1b543d00701086662bd5f09d47c8aa10e67a034b 100644 (file)
@@ -269,9 +269,9 @@ int stream_sock_read(int fd) {
 #endif
        cur_read = 0;
        while (1) {
-               max = buffer_max_len(b) - buffer_len(b);
+               max = bi_avail(b);
 
-               if (max <= 0) {
+               if (!max) {
                        b->flags |= BF_FULL;
                        si->flags |= SI_FL_WAIT_ROOM;
                        break;
@@ -318,7 +318,7 @@ int stream_sock_read(int fd) {
                        b->flags |= BF_READ_PARTIAL;
                        b->total += ret;
 
-                       if (buffer_len(b) >= buffer_max_len(b)) {
+                       if (bi_full(b)) {
                                /* The buffer is now full, there's no point in going through
                                 * the loop again.
                                 */
@@ -646,7 +646,7 @@ static int stream_sock_write_loop(struct stream_interface *si, struct buffer *b)
                                /* optimize data alignment in the buffer */
                                b->p = b->data;
 
-                       if (likely(buffer_len(b) < buffer_max_len(b)))
+                       if (likely(!bi_full(b)))
                                b->flags &= ~BF_FULL;
 
                        if (!b->o) {