diff --git a/include/common/buffer.h b/include/common/buffer.h index cea31aa5f..346521a55 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -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) diff --git a/include/proto/channel.h b/include/proto/channel.h index e2424f147..28ca7c61a 100644 --- a/include/proto/channel.h +++ b/include/proto/channel.h @@ -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 */ diff --git a/src/channel.c b/src/channel.c index 04301fba2..e9c5e12fd 100644 --- a/src/channel.c +++ b/src/channel.c @@ -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; diff --git a/src/payload.c b/src/payload.c index f62163c41..fe9fddaed 100644 --- a/src/payload.c +++ b/src/payload.c @@ -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; diff --git a/src/stream_interface.c b/src/stream_interface.c index bafb0d2c0..19adcee9a 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -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; }