]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: channel: rename channel_full() to !channel_may_recv()
authorWilly Tarreau <w@1wt.eu>
Tue, 13 Jan 2015 19:20:10 +0000 (20:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 14 Jan 2015 17:41:33 +0000 (18:41 +0100)
This function's name was poorly chosen and is confusing to the point of
being suspiciously used at some places. The operations it does always
consider the ability to forward pending input data before receiving new
data. This is not obvious at all, especially at some places where it was
used when consuming outgoing data to know if the buffer has any chance
to ever get the missing data. The code needs to be re-audited with that
in mind. Care must be taken with existing code since the polarity of the
function was switched with the renaming.

include/common/buffer.h
include/proto/channel.h
src/channel.c
src/payload.c
src/stream_interface.c

index cea31aa5f538269e2994c1b3a4a7231617c0b30b..346521a555f0bf07cf0ba8e091cb103c9d90d3c2 100644 (file)
@@ -171,7 +171,7 @@ static inline int buffer_empty(const struct buffer *buf)
  * space, and that the reserved space is always considered as not usable. This
  * information alone cannot be used as a general purpose free space indicator.
  * However it accurately indicates that too many data were fed in the buffer
- * for an analyzer for instance. See the channel_full() function for a more
+ * for an analyzer for instance. See the channel_may_recv() function for a more
  * generic function taking everything into account.
  */
 static inline int buffer_full(const struct buffer *b, unsigned int reserve)
index e2424f14741b1fe08fb9b3de72cd4fae3a8a5248..28ca7c61a2a2dc88139ed8be650bec7c1666ef52 100644 (file)
@@ -153,7 +153,7 @@ static inline int channel_in_transit(const struct channel *chn)
        return ret;
 }
 
-/* Returns non-zero if the buffer input is considered full. This is used to
+/* Returns non-zero if the channel can still receive data. This is used to
  * decide when to stop reading into a buffer when we want to ensure that we
  * leave the reserve untouched after all pending outgoing data are forwarded.
  * The reserved space is taken into account if ->to_forward indicates that an
@@ -162,17 +162,17 @@ static inline int channel_in_transit(const struct channel *chn)
  * 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 channel_full(const struct channel *chn)
+static inline int channel_may_recv(const struct channel *chn)
 {
        int rem = chn->buf->size;
 
        if (chn->buf == &buf_empty)
-               return 0;
+               return 1;
 
        rem -= chn->buf->o;
        rem -= chn->buf->i;
        if (!rem)
-               return 1; /* buffer already full */
+               return 0; /* buffer already full */
 
        /* now we know there's some room left, verify if we're touching
         * the reserve with some permanent input data.
@@ -180,12 +180,12 @@ static inline int channel_full(const struct channel *chn)
        if (chn->to_forward >= chn->buf->i ||
            (CHN_INFINITE_FORWARD < MAX_RANGE(typeof(chn->buf->i)) && // just there to ensure gcc
             chn->to_forward == CHN_INFINITE_FORWARD))                // avoids the useless second
-               return 0;                                             // test whenever possible
+               return 1;                                             // test whenever possible
 
        rem -= global.tune.maxrewrite;
        rem += chn->buf->o;
        rem += chn->to_forward;
-       return rem <= 0;
+       return rem > 0;
 }
 
 /* Returns true if the channel's input is already closed */
index 04301fba2b0c364933c9cdb9419a42d255fb214c..e9c5e12fdcadbc1e938275b4fecd234e15601b86 100644 (file)
@@ -121,7 +121,7 @@ int bi_putchr(struct channel *chn, char c)
        if (unlikely(channel_input_closed(chn)))
                return -2;
 
-       if (channel_full(chn)) {
+       if (!channel_may_recv(chn)) {
                chn->flags |= CF_WAKE_WRITE;
                return -1;
        }
@@ -282,7 +282,7 @@ int bo_getline(struct channel *chn, char *str, int len)
                p = buffer_wrap_add(chn->buf, p + 1);
        }
        if (ret > 0 && ret < len &&
-           (ret < chn->buf->o || !channel_full(chn)) &&
+           (ret < chn->buf->o || channel_may_recv(chn)) &&
            *(str-1) != '\n' &&
            !(chn->flags & (CF_SHUTW|CF_SHUTW_NOW)))
                ret = 0;
index f62163c4143caa293f902ceb877e1596993ebb12..fe9fddaedd76e7ee0f225432bc9edea483e4f2af 100644 (file)
@@ -612,7 +612,7 @@ smp_fetch_payload(struct proxy *px, struct session *s, void *l7, unsigned int op
        smp->type = SMP_T_BIN;
        smp->flags = SMP_F_VOLATILE | SMP_F_CONST;
        chunk_initlen(&smp->data.str, chn->buf->p + buf_offset, 0, buf_size ? buf_size : (chn->buf->i - buf_offset));
-       if (!buf_size && !channel_full(chn) && !channel_input_closed(chn))
+       if (!buf_size && channel_may_recv(chn) && !channel_input_closed(chn))
                smp->flags |= SMP_F_MAY_CHANGE;
 
        return 1;
index bafb0d2c03d6f79234b2a8cddf9923c8e57c932b..19adcee9a171c774b30b3370e6063a3208636e31 100644 (file)
@@ -152,7 +152,7 @@ static void stream_int_update_embedded(struct stream_interface *si)
            channel_is_empty(si->ob))
                si_shutw(si);
 
-       if ((si->ob->flags & (CF_SHUTW|CF_SHUTW_NOW)) == 0 && !channel_full(si->ob))
+       if ((si->ob->flags & (CF_SHUTW|CF_SHUTW_NOW)) == 0 && channel_may_recv(si->ob))
                si->flags |= SI_FL_WAIT_DATA;
 
        /* we're almost sure that we need some space if the buffer is not
@@ -175,7 +175,7 @@ static void stream_int_update_embedded(struct stream_interface *si)
        /* save flags to detect changes */
        old_flags = si->flags;
        if (likely((si->ob->flags & (CF_SHUTW|CF_WRITE_PARTIAL|CF_DONT_READ)) == CF_WRITE_PARTIAL &&
-                  !channel_full(si->ob) &&
+                  channel_may_recv(si->ob) &&
                   (si->ob->prod->flags & SI_FL_WAIT_ROOM)))
                si_chk_rcv(si->ob->prod);
 
@@ -184,7 +184,7 @@ static void stream_int_update_embedded(struct stream_interface *si)
             (si->ib->buf->i == 0 && (si->ib->cons->flags & SI_FL_WAIT_DATA)))) {
                si_chk_snd(si->ib->cons);
                /* check if the consumer has freed some space */
-               if (!channel_full(si->ib) && !si->ib->pipe)
+               if (channel_may_recv(si->ib) && !si->ib->pipe)
                        si->flags &= ~SI_FL_WAIT_ROOM;
        }
 
@@ -315,7 +315,7 @@ static void stream_int_chk_rcv(struct stream_interface *si)
        if (unlikely(si->state != SI_ST_EST || (ib->flags & (CF_SHUTR|CF_DONT_READ))))
                return;
 
-       if (channel_full(ib) || ib->pipe) {
+       if (!channel_may_recv(ib) || ib->pipe) {
                /* stop reading */
                si->flags |= SI_FL_WAIT_ROOM;
        }
@@ -570,7 +570,7 @@ static int si_conn_wake_cb(struct connection *conn)
                si->ob->wex = TICK_ETERNITY;
        }
 
-       if ((si->ob->flags & (CF_SHUTW|CF_SHUTW_NOW)) == 0 && !channel_full(si->ob))
+       if ((si->ob->flags & (CF_SHUTW|CF_SHUTW_NOW)) == 0 && channel_may_recv(si->ob))
                si->flags |= SI_FL_WAIT_DATA;
 
        if (si->ob->flags & CF_WRITE_ACTIVITY) {
@@ -585,7 +585,7 @@ static int si_conn_wake_cb(struct connection *conn)
                                si->ib->rex = tick_add_ifset(now_ms, si->ib->rto);
 
                if (likely((si->ob->flags & (CF_SHUTW|CF_WRITE_PARTIAL|CF_DONT_READ)) == CF_WRITE_PARTIAL &&
-                          !channel_full(si->ob) &&
+                          channel_may_recv(si->ob) &&
                           (si->ob->prod->flags & SI_FL_WAIT_ROOM)))
                        si_chk_rcv(si->ob->prod);
        }
@@ -607,7 +607,7 @@ static int si_conn_wake_cb(struct connection *conn)
                /* check if the consumer has freed some space either in the
                 * buffer or in the pipe.
                 */
-               if (!channel_full(si->ib) &&
+               if (channel_may_recv(si->ib) &&
                    (!last_len || !si->ib->pipe || si->ib->pipe->data < last_len))
                        si->flags &= ~SI_FL_WAIT_ROOM;
        }
@@ -617,7 +617,7 @@ static int si_conn_wake_cb(struct connection *conn)
                si->ib->rex = TICK_ETERNITY;
        }
        else if ((si->ib->flags & (CF_SHUTR|CF_READ_PARTIAL|CF_DONT_READ)) == CF_READ_PARTIAL &&
-                !channel_full(si->ib)) {
+                channel_may_recv(si->ib)) {
                /* we must re-enable reading if si_chk_snd() has freed some space */
                __conn_data_want_recv(conn);
                if (!(si->ib->flags & CF_READ_NOEXP) && tick_isset(si->ib->rex))
@@ -740,7 +740,7 @@ void stream_int_update_conn(struct stream_interface *si)
        /* Check if we need to close the read side */
        if (!(ib->flags & CF_SHUTR)) {
                /* Read not closed, update FD status and timeout for reads */
-               if ((ib->flags & CF_DONT_READ) || channel_full(ib)) {
+               if ((ib->flags & CF_DONT_READ) || !channel_may_recv(ib)) {
                        /* stop reading */
                        if (!(si->flags & SI_FL_WAIT_ROOM)) {
                                if (!(ib->flags & CF_DONT_READ)) /* full */
@@ -941,7 +941,7 @@ static void stream_int_chk_rcv_conn(struct stream_interface *si)
 
        conn_refresh_polling_flags(conn);
 
-       if ((ib->flags & CF_DONT_READ) || channel_full(ib)) {
+       if ((ib->flags & CF_DONT_READ) || !channel_may_recv(ib)) {
                /* stop reading */
                if (!(ib->flags & CF_DONT_READ)) /* full */
                        si->flags |= SI_FL_WAIT_ROOM;
@@ -1208,7 +1208,7 @@ static void si_conn_recv_cb(struct connection *conn)
                chn->flags |= CF_READ_PARTIAL;
                chn->total += ret;
 
-               if (channel_full(chn)) {
+               if (!channel_may_recv(chn)) {
                        si->flags |= SI_FL_WAIT_ROOM;
                        break;
                }