]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: replace buffer_empty() with b_empty() or c_empty()
authorWilly Tarreau <w@1wt.eu>
Tue, 10 Jul 2018 07:53:31 +0000 (09:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:41 +0000 (16:23 +0200)
For the same consistency reasons, let's use b_empty() at the few places
where an empty buffer is expected, or c_empty() if it's done on a channel.
Some of these places were there to realign the buffer so
{b,c}_realign_if_empty() was used instead.

include/common/buffer.h
include/proto/channel.h
src/buffer.c
src/channel.c
src/raw_sock.c
src/ssl_sock.c
src/stream.c

index e0b6c962f0a1e9130c17675452d005c228a1ebf2..a05d58d7ad9dde2d97026756aade5c0aada66bd6 100644 (file)
@@ -61,12 +61,6 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to);
 
 /***** FIXME: OLD API BELOW *****/
 
-/* Return non-zero only if the buffer is empty */
-static inline int buffer_empty(const struct buffer *buf)
-{
-       return !b_data(buf);
-}
-
 /* Returns non-zero if the buffer's INPUT is considered full, which means that
  * it holds at least as much INPUT data as (size - reserve). This also means
  * that data that are scheduled for output are considered as potential free
index 026574f512512d7d9a2e229bce8a8421b18cf452..850f900dcd3c603340a87df3e7ae6738e2dd6cdf 100644 (file)
@@ -685,7 +685,7 @@ static inline int channel_alloc_buffer(struct channel *chn, struct buffer_wait *
  * to wake up as many streams/applets as possible. */
 static inline void channel_release_buffer(struct channel *chn, struct buffer_wait *wait)
 {
-       if (chn->buf->size && buffer_empty(chn->buf)) {
+       if (c_size(chn) && c_empty(chn)) {
                b_free(&chn->buf);
                offer_buffers(wait->target, tasks_run_queue);
        }
@@ -728,8 +728,7 @@ static inline void channel_slow_realign(struct channel *chn, char *swap)
 static inline void co_skip(struct channel *chn, int len)
 {
        b_del(chn->buf, len);
-       if (buffer_empty(chn->buf))
-               chn->buf->p = chn->buf->data;
+       c_realign_if_empty(chn);
 
        /* notify that some data was written to the SI from the buffer */
        chn->flags |= CF_WRITE_PARTIAL | CF_WRITE_EVENT;
index 416cb4c2c30b67033a2377bd11801632662ed17d..16372bf07cb1e5805f2e81d9abde03dbe30e9ca7 100644 (file)
@@ -102,9 +102,7 @@ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int
                memcpy(pos, str, len);
 
        b->i += delta;
-
-       if (buffer_empty(b))
-               b->p = b->data;
+       b_realign_if_empty(b);
 
        return delta;
 }
index c5a51f771d243582c800323dbd9a174ec234cf10..1efab9c95ca0a0ff535e6aaf4ab066c5a0bb6c22 100644 (file)
@@ -205,7 +205,7 @@ struct buffer *ci_swpbuf(struct channel *chn, struct buffer *buf)
        if (unlikely(channel_input_closed(chn)))
                return NULL;
 
-       if (!chn->buf->size || !buffer_empty(chn->buf))
+       if (!c_size(chn) || !c_empty(chn))
                return buf;
 
        old = chn->buf;
index 477862eda4cc40d3f10bfc00bcc912f27af28f64..3ae76562ed87b6a5cd0d15873294fc60912a48d5 100644 (file)
@@ -276,9 +276,7 @@ static size_t raw_sock_to_buf(struct connection *conn, struct buffer *buf, size_
                }
        }
 
-       /* let's realign the buffer to optimize I/O */
-       if (buffer_empty(buf))
-               buf->p = buf->data;
+       b_realign_if_empty(buf);
 
        /* read the largest possible block. For this, we perform only one call
         * to recv() unless the buffer wraps and we exactly fill the first hunk,
index 42cb72fb49a797d853b61a77ee700c9fcb764206..9aa101b2ba090e609e6fc9bad24da17475d0a8fe 100644 (file)
@@ -5351,10 +5351,7 @@ static size_t ssl_sock_to_buf(struct connection *conn, struct buffer *buf, size_
                /* a handshake was requested */
                return 0;
 
-       /* let's realign the buffer to optimize I/O */
-       if (buffer_empty(buf)) {
-               buf->p = buf->data;
-       }
+       b_realign_if_empty(buf);
 
        /* read the largest possible block. For this, we perform only one call
         * to recv() unless the buffer wraps and we exactly fill the first hunk,
index 30bfc6721c16e088a1b0cc271ea59fbac023a506..e958423b50e11ac20d9249b69e745fccba774883 100644 (file)
@@ -456,11 +456,11 @@ void stream_release_buffers(struct stream *s)
 {
        int offer = 0;
 
-       if (s->req.buf->size && buffer_empty(s->req.buf)) {
+       if (c_size(&s->req) && c_empty(&s->req)) {
                offer = 1;
                b_free(&s->req.buf);
        }
-       if (s->res.buf->size && buffer_empty(s->res.buf)) {
+       if (c_size(&s->res) && c_empty(&s->res)) {
                offer = 1;
                b_free(&s->res.buf);
        }