MINOR: tree-wide: Simplifiy some tests on SHUT flags by accessing SCs directly
At many places, we simplify the tests on SHUT flags to remove calls to
chn_prod() or chn_cons() function because the corresponding SC is available.
diff --git a/src/stconn.c b/src/stconn.c
index 5d94646..061a003 100644
--- a/src/stconn.c
+++ b/src/stconn.c
@@ -507,7 +507,7 @@
static inline int sc_cond_forward_shutw(struct stconn *sc)
{
/* The close must not be forwarded */
- if (!(chn_prod(sc_ic(sc))->flags & SC_FL_SHUTR) || !(sc->flags & SC_FL_NOHALF))
+ if (!(sc->flags & SC_FL_SHUTR) || !(sc->flags & SC_FL_NOHALF))
return 0;
if (!channel_is_empty(sc_ic(sc))) {
@@ -534,17 +534,17 @@
{
struct channel *ic = sc_ic(sc);
- if (chn_prod(ic)->flags & SC_FL_SHUTR)
+ if (sc->flags & SC_FL_SHUTR)
return;
- chn_prod(ic)->flags |= SC_FL_SHUTR;
+ sc->flags |= SC_FL_SHUTR;
ic->flags |= CF_READ_EVENT;
sc_ep_report_read_activity(sc);
if (!sc_state_in(sc->state, SC_SB_CON|SC_SB_RDY|SC_SB_EST))
return;
- if (chn_cons(sc_oc(sc))->flags & SC_FL_SHUTW) {
+ if (sc->flags & SC_FL_SHUTW) {
sc->state = SC_ST_DIS;
if (sc->flags & SC_FL_ISBACK)
__sc_strm(sc)->conn_exp = TICK_ETERNITY;
@@ -569,10 +569,10 @@
struct channel *ic = sc_ic(sc);
struct channel *oc = sc_oc(sc);
- chn_cons(oc)->flags &= ~SC_FL_SHUTW_NOW;
- if (chn_cons(oc)->flags & SC_FL_SHUTW)
+ sc->flags &= ~SC_FL_SHUTW_NOW;
+ if (sc->flags & SC_FL_SHUTW)
return;
- chn_cons(oc)->flags |= SC_FL_SHUTW;
+ sc->flags |= SC_FL_SHUTW;
oc->flags |= CF_WRITE_EVENT;
sc_set_hcto(sc);
@@ -586,7 +586,7 @@
* no risk so we close both sides immediately.
*/
if (!sc_ep_test(sc, SE_FL_ERROR) && !(sc->flags & SC_FL_NOLINGER) &&
- !(chn_prod(ic)->flags & SC_FL_SHUTR) && !(ic->flags & CF_DONT_READ))
+ !(sc->flags & SC_FL_SHUTR) && !(ic->flags & CF_DONT_READ))
return;
__fallthrough;
@@ -599,7 +599,7 @@
__fallthrough;
default:
sc->flags &= ~SC_FL_NOLINGER;
- chn_prod(ic)->flags |= SC_FL_SHUTR;
+ sc->flags |= SC_FL_SHUTR;
if (sc->flags & SC_FL_ISBACK)
__sc_strm(sc)->conn_exp = TICK_ETERNITY;
}
@@ -630,7 +630,7 @@
{
struct channel *oc = sc_oc(sc);
- if (unlikely(sc->state != SC_ST_EST || (chn_cons(oc)->flags & SC_FL_SHUTW)))
+ if (unlikely(sc->state != SC_ST_EST || (sc->flags & SC_FL_SHUTW)))
return;
if (!sc_ep_test(sc, SE_FL_WAIT_DATA) || /* not waiting for data */
@@ -661,15 +661,15 @@
BUG_ON(!sc_conn(sc));
- if (chn_prod(ic)->flags & SC_FL_SHUTR)
+ if (sc->flags & SC_FL_SHUTR)
return;
- chn_prod(ic)->flags |= SC_FL_SHUTR;
+ sc->flags |= SC_FL_SHUTR;
ic->flags |= CF_READ_EVENT;
if (!sc_state_in(sc->state, SC_SB_CON|SC_SB_RDY|SC_SB_EST))
return;
- if (chn_cons(sc_oc(sc))->flags & SC_FL_SHUTW) {
+ if (sc->flags & SC_FL_SHUTW) {
sc_conn_shut(sc);
sc->state = SC_ST_DIS;
if (sc->flags & SC_FL_ISBACK)
@@ -694,10 +694,10 @@
BUG_ON(!sc_conn(sc));
- chn_cons(oc)->flags &= ~SC_FL_SHUTW_NOW;
- if (chn_cons(oc)->flags & SC_FL_SHUTW)
+ sc->flags &= ~SC_FL_SHUTW_NOW;
+ if (sc->flags & SC_FL_SHUTW)
return;
- chn_cons(oc)->flags |= SC_FL_SHUTW;
+ sc->flags |= SC_FL_SHUTW;
oc->flags |= CF_WRITE_EVENT;
sc_set_hcto(sc);
@@ -731,7 +731,7 @@
*/
sc_conn_shutw(sc, CO_SHW_NORMAL);
- if (!(chn_prod(ic)->flags & SC_FL_SHUTR) && !(ic->flags & CF_DONT_READ))
+ if (!(sc->flags & SC_FL_SHUTR) && !(ic->flags & CF_DONT_READ))
return;
}
@@ -749,7 +749,7 @@
__fallthrough;
default:
sc->flags &= ~SC_FL_NOLINGER;
- chn_prod(ic)->flags |= SC_FL_SHUTR;
+ sc->flags |= SC_FL_SHUTR;
if (sc->flags & SC_FL_ISBACK)
__sc_strm(sc)->conn_exp = TICK_ETERNITY;
}
@@ -783,7 +783,7 @@
BUG_ON(!sc_conn(sc));
if (unlikely(!sc_state_in(sc->state, SC_SB_RDY|SC_SB_EST) ||
- (chn_cons(oc)->flags & SC_FL_SHUTW)))
+ (sc->flags & SC_FL_SHUTW)))
return;
if (unlikely(channel_is_empty(oc))) /* called with nothing to send ! */
@@ -813,13 +813,13 @@
* chunk and need to close.
*/
if ((oc->flags & CF_AUTO_CLOSE) &&
- ((chn_cons(oc)->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)) == SC_FL_SHUTW_NOW) &&
+ ((sc->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)) == SC_FL_SHUTW_NOW) &&
sc_state_in(sc->state, SC_SB_RDY|SC_SB_EST)) {
sc_shutw(sc);
goto out_wakeup;
}
- if ((chn_cons(oc)->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)) == 0)
+ if ((sc->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)) == 0)
sc_ep_set(sc, SE_FL_WAIT_DATA);
}
else {
@@ -832,7 +832,7 @@
/* in case of special condition (error, shutdown, end of write...), we
* have to notify the task.
*/
- if (likely((chn_cons(oc)->flags & SC_FL_SHUTW) ||
+ if (likely((sc->flags & SC_FL_SHUTW) ||
((oc->flags & CF_WRITE_EVENT) && sc->state < SC_ST_EST) ||
((oc->flags & CF_WAKE_WRITE) &&
((channel_is_empty(oc) && !oc->to_forward) ||
@@ -857,9 +857,9 @@
BUG_ON(!sc_appctx(sc));
- if (chn_prod(ic)->flags & SC_FL_SHUTR)
+ if (sc->flags & SC_FL_SHUTR)
return;
- chn_prod(ic)->flags |= SC_FL_SHUTR;
+ sc->flags |= SC_FL_SHUTR;
ic->flags |= CF_READ_EVENT;
/* Note: on shutr, we don't call the applet */
@@ -867,7 +867,7 @@
if (!sc_state_in(sc->state, SC_SB_CON|SC_SB_RDY|SC_SB_EST))
return;
- if (chn_cons(sc_oc(sc))->flags & SC_FL_SHUTW) {
+ if (sc->flags & SC_FL_SHUTW) {
appctx_shut(__sc_appctx(sc));
sc->state = SC_ST_DIS;
if (sc->flags & SC_FL_ISBACK)
@@ -891,10 +891,10 @@
BUG_ON(!sc_appctx(sc));
- chn_cons(oc)->flags &= ~SC_FL_SHUTW_NOW;
- if (chn_cons(oc)->flags & SC_FL_SHUTW)
+ sc->flags &= ~SC_FL_SHUTW_NOW;
+ if (sc->flags & SC_FL_SHUTW)
return;
- chn_cons(oc)->flags |= SC_FL_SHUTW;
+ sc->flags |= SC_FL_SHUTW;
oc->flags |= CF_WRITE_EVENT;
sc_set_hcto(sc);
@@ -911,7 +911,7 @@
* no risk so we close both sides immediately.
*/
if (!sc_ep_test(sc, SE_FL_ERROR) && !(sc->flags & SC_FL_NOLINGER) &&
- !(chn_prod(ic)->flags & SC_FL_SHUTR) &&
+ !(sc->flags & SC_FL_SHUTR) &&
!(ic->flags & CF_DONT_READ))
return;
@@ -926,7 +926,7 @@
__fallthrough;
default:
sc->flags &= ~SC_FL_NOLINGER;
- chn_prod(ic)->flags |= SC_FL_SHUTR;
+ sc->flags |= SC_FL_SHUTR;
if (sc->flags & SC_FL_ISBACK)
__sc_strm(sc)->conn_exp = TICK_ETERNITY;
}
@@ -952,7 +952,7 @@
BUG_ON(!sc_appctx(sc));
- if (unlikely(sc->state != SC_ST_EST || (chn_cons(oc)->flags & SC_FL_SHUTW)))
+ if (unlikely(sc->state != SC_ST_EST || (sc->flags & SC_FL_SHUTW)))
return;
/* we only wake the applet up if it was waiting for some data and is ready to consume it */
@@ -979,7 +979,7 @@
{
struct channel *ic = sc_ic(sc);
- if (chn_prod(ic)->flags & SC_FL_SHUTR)
+ if (sc->flags & SC_FL_SHUTR)
return;
/* Read not closed, update FD status and timeout for reads */
@@ -1004,14 +1004,14 @@
{
struct channel *oc = sc_oc(sc);
- if (chn_cons(oc)->flags & SC_FL_SHUTW)
+ if (sc->flags & SC_FL_SHUTW)
return;
/* Write not closed, update FD status and timeout for writes */
if (channel_is_empty(oc)) {
/* stop writing */
if (!sc_ep_test(sc, SE_FL_WAIT_DATA)) {
- if ((chn_cons(oc)->flags & SC_FL_SHUTW_NOW) == 0)
+ if ((sc->flags & SC_FL_SHUTW_NOW) == 0)
sc_ep_set(sc, SE_FL_WAIT_DATA);
}
return;
@@ -1042,7 +1042,7 @@
if (channel_is_empty(oc)) {
struct connection *conn = sc_conn(sc);
- if (((chn_cons(oc)->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)) == SC_FL_SHUTW_NOW) &&
+ if (((sc->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)) == SC_FL_SHUTW_NOW) &&
(sc->state == SC_ST_EST) && (!conn || !(conn->flags & (CO_FL_WAIT_XPRT | CO_FL_EARLY_SSL_HS))))
sc_shutw(sc);
}
@@ -1050,9 +1050,9 @@
/* indicate that we may be waiting for data from the output channel or
* we're about to close and can't expect more data if SC_FL_SHUTW_NOW is there.
*/
- if (!(chn_cons(oc)->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)))
+ if (!(sc->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)))
sc_ep_set(sc, SE_FL_WAIT_DATA);
- else if ((chn_cons(oc)->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)) == SC_FL_SHUTW_NOW)
+ else if ((sc->flags & (SC_FL_SHUTW|SC_FL_SHUTW_NOW)) == SC_FL_SHUTW_NOW)
sc_ep_clr(sc, SE_FL_WAIT_DATA);
if (oc->flags & CF_DONT_READ)
@@ -1108,17 +1108,17 @@
* data received and no fast-forwarding (CF_READ_EVENT + !to_forward)
* read event while consumer side is not established (CF_READ_EVENT + sco->state != SC_ST_EST)
*/
- ((ic->flags & CF_READ_EVENT) && ((sc->flags & SC_FL_EOI) || (chn_prod(ic)->flags & SC_FL_SHUTR) || !ic->to_forward || sco->state != SC_ST_EST)) ||
+ ((ic->flags & CF_READ_EVENT) && ((sc->flags & SC_FL_EOI) || (sc->flags & SC_FL_SHUTR) || !ic->to_forward || sco->state != SC_ST_EST)) ||
sc_ep_test(sc, SE_FL_ERROR) ||
/* changes on the consumption side */
sc_ep_test(sc, SE_FL_ERR_PENDING) ||
((oc->flags & CF_WRITE_EVENT) &&
((sc->state < SC_ST_EST) ||
- (chn_cons(oc)->flags & SC_FL_SHUTW) ||
+ (sc->flags & SC_FL_SHUTW) ||
(((oc->flags & CF_WAKE_WRITE) ||
(!(oc->flags & CF_AUTO_CLOSE) &&
- !(chn_cons(oc)->flags & (SC_FL_SHUTW_NOW|SC_FL_SHUTW)))) &&
+ !(sc->flags & (SC_FL_SHUTW_NOW|SC_FL_SHUTW)))) &&
(sco->state != SC_ST_EST ||
(channel_is_empty(oc) && !oc->to_forward)))))) {
task_wakeup(task, TASK_WOKEN_IO);
@@ -1136,20 +1136,19 @@
static void sc_conn_read0(struct stconn *sc)
{
struct channel *ic = sc_ic(sc);
- struct channel *oc = sc_oc(sc);
BUG_ON(!sc_conn(sc));
- if (chn_prod(ic)->flags & SC_FL_SHUTR)
+ if (sc->flags & SC_FL_SHUTR)
return;
- chn_prod(ic)->flags |= SC_FL_SHUTR;
+ sc->flags |= SC_FL_SHUTR;
ic->flags |= CF_READ_EVENT;
sc_ep_report_read_activity(sc);
if (!sc_state_in(sc->state, SC_SB_CON|SC_SB_RDY|SC_SB_EST))
return;
- if (chn_cons(oc)->flags & SC_FL_SHUTW)
+ if (sc->flags & SC_FL_SHUTW)
goto do_close;
if (sc_cond_forward_shutw(sc)) {
@@ -1166,8 +1165,8 @@
/* OK we completely close the socket here just as if we went through sc_shut[rw]() */
sc_conn_shut(sc);
- chn_cons(oc)->flags &= ~SC_FL_SHUTW_NOW;
- chn_cons(oc)->flags |= SC_FL_SHUTW;
+ sc->flags &= ~SC_FL_SHUTW_NOW;
+ sc->flags |= SC_FL_SHUTW;
sc->state = SC_ST_DIS;
if (sc->flags & SC_FL_ISBACK)
@@ -1199,7 +1198,7 @@
return 0;
/* maybe we were called immediately after an asynchronous shutr */
- if (chn_prod(ic)->flags & SC_FL_SHUTR)
+ if (sc->flags & SC_FL_SHUTR)
return 1;
/* we must wait because the mux is not installed yet */
@@ -1330,7 +1329,7 @@
*/
while (sc_ep_test(sc, SE_FL_RCV_MORE) ||
(!(conn->flags & CO_FL_HANDSHAKE) &&
- (!sc_ep_test(sc, SE_FL_ERROR | SE_FL_EOS)) && !(chn_prod(ic)->flags & SC_FL_SHUTR))) {
+ (!sc_ep_test(sc, SE_FL_ERROR | SE_FL_EOS)) && !(sc->flags & SC_FL_SHUTR))) {
int cur_flags = flags;
/* Compute transient CO_RFL_* flags */
@@ -1494,7 +1493,7 @@
if (sc_ep_test(sc, SE_FL_ERROR))
ret = 1;
else if (!(sc->flags & (SC_FL_WONT_READ|SC_FL_NEED_BUFF|SC_FL_NEED_ROOM)) &&
- !(chn_prod(ic)->flags & SC_FL_SHUTR)) {
+ !(sc->flags & SC_FL_SHUTR)) {
/* Subscribe to receive events if we're blocking on I/O */
conn->mux->subscribe(sc, SUB_RETRY_RECV, &sc->wait_event);
se_have_no_more_data(sc->sedesc);
@@ -1564,7 +1563,7 @@
return 0;
/* we might have been called just after an asynchronous shutw */
- if (chn_cons(oc)->flags & SC_FL_SHUTW)
+ if (sc->flags & SC_FL_SHUTW)
return 1;
/* we must wait because the mux is not installed yet */
@@ -1609,10 +1608,10 @@
((oc->to_forward && oc->to_forward != CHN_INFINITE_FORWARD) ||
(sc->flags & SC_FL_SND_EXP_MORE) ||
(IS_HTX_STRM(s) &&
- (!(sco->flags & SC_FL_EOI) && !(chn_prod(oc)->flags & SC_FL_SHUTR) && htx_expect_more(htxbuf(&oc->buf)))))) ||
+ (!(sco->flags & (SC_FL_EOI|SC_FL_SHUTR)) && htx_expect_more(htxbuf(&oc->buf)))))) ||
((oc->flags & CF_ISRESP) &&
(oc->flags & CF_AUTO_CLOSE) &&
- (chn_cons(oc)->flags & SC_FL_SHUTW_NOW)))
+ (sc->flags & SC_FL_SHUTW_NOW)))
send_flag |= CO_SFL_MSG_MORE;
if (oc->flags & CF_STREAMER)
@@ -1696,7 +1695,7 @@
oc->flags &= ~CF_WRITE_EVENT;
- if (chn_cons(oc)->flags & SC_FL_SHUTW)
+ if (sc->flags & SC_FL_SHUTW)
return;
if (channel_is_empty(oc))
@@ -1774,7 +1773,7 @@
* wake callback. Otherwise sc_conn_recv()/sc_conn_send() already take
* care of it.
*/
- if (sc_ep_test(sc, SE_FL_EOS) && !(chn_prod(ic)->flags & SC_FL_SHUTR)) {
+ if (sc_ep_test(sc, SE_FL_EOS) && !(sc->flags & SC_FL_SHUTR)) {
/* we received a shutdown */
if (ic->flags & CF_AUTO_CLOSE)
channel_shutw_now(ic);
@@ -1853,7 +1852,7 @@
/* If the applet wants to write and the channel is closed, it's a
* broken pipe and it must be reported.
*/
- if (!sc_ep_test(sc, SE_FL_HAVE_NO_DATA) && (chn_prod(ic)->flags & SC_FL_SHUTR))
+ if (!sc_ep_test(sc, SE_FL_HAVE_NO_DATA) && (sc->flags & SC_FL_SHUTR))
sc_ep_set(sc, SE_FL_ERROR);
/* automatically mark the applet having data available if it reported