]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: replace buffer_not_empty() with b_data() or c_data()
authorWilly Tarreau <w@1wt.eu>
Tue, 10 Jul 2018 07:50:25 +0000 (09:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:41 +0000 (16:23 +0200)
It's mostly for consistency as many places already use one of these instead.

include/common/buffer.h
src/buffer.c
src/proto_http.c
src/stream_interface.c

index 44b18838408ab930c2fc3efe57abaee37a4ad48b..e0b6c962f0a1e9130c17675452d005c228a1ebf2 100644 (file)
@@ -61,16 +61,10 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to);
 
 /***** FIXME: OLD API BELOW *****/
 
-/* Return non-zero only if the buffer is not empty */
-static inline int buffer_not_empty(const struct buffer *buf)
-{
-       return buf->i | buf->o;
-}
-
 /* Return non-zero only if the buffer is empty */
 static inline int buffer_empty(const struct buffer *buf)
 {
-       return !buffer_not_empty(buf);
+       return !b_data(buf);
 }
 
 /* Returns non-zero if the buffer's INPUT is considered full, which means that
index d6320c6852f6b462f6e7277fb35d5756f9b6dc31..416cb4c2c30b67033a2377bd11801632662ed17d 100644 (file)
@@ -89,7 +89,7 @@ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int
        if (b_tail(b) + delta > b->data + b->size)
                return 0;  /* no space left */
 
-       if (buffer_not_empty(b) &&
+       if (b_data(b) &&
            b_tail(b) + delta > b_head(b) &&
            b_head(b) >= b_tail(b))
                return 0;  /* no space left before wrapping data */
@@ -128,7 +128,7 @@ int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len)
        if (b_tail(b) + delta >= b->data + b->size)
                return 0;  /* no space left */
 
-       if (buffer_not_empty(b) &&
+       if (b_data(b) &&
            b_tail(b) + delta > b_head(b) &&
            b_head(b) >= b_tail(b))
                return 0;  /* no space left before wrapping data */
index 78e0badd5f1fdabfab1367832929cf54292bba54..3d83e1b4b73a79bb111712b49781599f4d93da98 100644 (file)
@@ -1631,7 +1631,7 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
        s->srv_error = http_return_srv_error;
 
        /* If there is data available for analysis, log the end of the idle time. */
-       if (buffer_not_empty(req->buf) && s->logs.t_idle == -1)
+       if (c_data(req) && s->logs.t_idle == -1)
                s->logs.t_idle = tv_ms_elapsed(&s->logs.tv_accept, &now) - s->logs.t_handshake;
 
        /* There's a protected area at the end of the buffer for rewriting
@@ -1639,7 +1639,7 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
         * protected area is affected, because we may have to move processed
         * data later, which is much more complicated.
         */
-       if (buffer_not_empty(req->buf) && msg->msg_state < HTTP_MSG_ERROR) {
+       if (c_data(req) && msg->msg_state < HTTP_MSG_ERROR) {
                if (txn->flags & TX_NOT_FIRST) {
                        if (unlikely(!channel_is_rewritable(req))) {
                                if (req->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_WRITE_ERROR|CF_WRITE_TIMEOUT))
@@ -4142,7 +4142,7 @@ int http_wait_for_request_body(struct stream *s, struct channel *req, int an_bit
                 * TRAILERS state.
                 */
                unsigned int chunk;
-               int ret = h1_parse_chunk_size(req->buf, co_data(req) + msg->next, b_data(req->buf), &chunk);
+               int ret = h1_parse_chunk_size(req->buf, co_data(req) + msg->next, c_data(req), &chunk);
 
                if (!ret)
                        goto missing_data;
@@ -5126,7 +5126,7 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
         * protected area is affected, because we may have to move processed
         * data later, which is much more complicated.
         */
-       if (buffer_not_empty(rep->buf) && msg->msg_state < HTTP_MSG_ERROR) {
+       if (c_data(rep) && msg->msg_state < HTTP_MSG_ERROR) {
                if (unlikely(!channel_is_rewritable(rep))) {
                        /* some data has still not left the buffer, wake us once that's done */
                        if (rep->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_WRITE_ERROR|CF_WRITE_TIMEOUT))
@@ -6353,7 +6353,7 @@ http_msg_forward_chunked_body(struct stream *s, struct http_msg *msg)
 
                case HTTP_MSG_CHUNK_CRLF:
                        /* we want the CRLF after the data */
-                       ret = h1_skip_chunk_crlf(chn->buf, co_data(chn) + msg->next, b_data(chn->buf));
+                       ret = h1_skip_chunk_crlf(chn->buf, co_data(chn) + msg->next, c_data(chn));
                        if (ret == 0)
                                goto missing_data_or_waiting;
                        if (ret < 0) {
@@ -6371,7 +6371,7 @@ http_msg_forward_chunked_body(struct stream *s, struct http_msg *msg)
                         * then set ->next to point to the body and switch to
                         * DATA or TRAILERS state.
                         */
-                       ret = h1_parse_chunk_size(chn->buf, co_data(chn) + msg->next, b_data(chn->buf), &chunk);
+                       ret = h1_parse_chunk_size(chn->buf, co_data(chn) + msg->next, c_data(chn), &chunk);
                        if (ret == 0)
                                goto missing_data_or_waiting;
                        if (ret < 0) {
index 2677b2f0ce99407e7052243c54fc2b617f89c9d3..6542f9f93c5efd49202310249e87d5c03b865148 100644 (file)
@@ -1115,7 +1115,7 @@ static void si_cs_recv_cb(struct conn_stream *cs)
        if (conn->xprt->rcv_pipe && conn->mux->rcv_pipe &&
            (ic->pipe || ic->to_forward >= MIN_SPLICE_FORWARD) &&
            ic->flags & CF_KERN_SPLICING) {
-               if (buffer_not_empty(ic->buf)) {
+               if (c_data(ic)) {
                        /* We're embarrassed, there are already data pending in
                         * the buffer and we don't want to have them at two
                         * locations at a time. Let's indicate we need some