mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-03 10:01:27 +00:00
MINOR: channel: rename channel_full() to !channel_may_recv()
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.
This commit is contained in:
parent
ba0902ede4
commit
3889fffe92
@ -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)
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user