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
* 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.
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 */
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
/* 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);
(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;
}
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;
}
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) {
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);
}
/* 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;
}
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))
/* 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 */
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;
chn->flags |= CF_READ_PARTIAL;
chn->total += ret;
- if (channel_full(chn)) {
+ if (!channel_may_recv(chn)) {
si->flags |= SI_FL_WAIT_ROOM;
break;
}