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.
This commit is contained in:
Christopher Faulet 2023-04-04 10:05:27 +02:00
parent 87633c3a11
commit 7faac7cf34
15 changed files with 81 additions and 85 deletions

View File

@ -286,9 +286,7 @@ static inline void sc_shutw(struct stconn *sc)
__attribute__((warn_unused_result)) __attribute__((warn_unused_result))
static inline int sc_is_recv_allowed(const struct stconn *sc) static inline int sc_is_recv_allowed(const struct stconn *sc)
{ {
struct channel *ic = sc_ic(sc); if (sc->flags & SC_FL_SHUTR)
if (chn_prod(ic)->flags & SC_FL_SHUTR)
return 0; return 0;
if (sc_ep_test(sc, SE_FL_APPLET_NEED_CONN)) if (sc_ep_test(sc, SE_FL_APPLET_NEED_CONN))
@ -365,9 +363,7 @@ static inline const char *sc_state_str(int state)
__attribute__((warn_unused_result)) __attribute__((warn_unused_result))
static inline int sc_is_send_allowed(const struct stconn *sc) static inline int sc_is_send_allowed(const struct stconn *sc)
{ {
struct channel *oc = sc_oc(sc); if (sc->flags & SC_FL_SHUTW)
if (chn_cons(oc)->flags & SC_FL_SHUTW)
return 0; return 0;
return !sc_ep_test(sc, SE_FL_WAIT_DATA | SE_FL_WONT_CONSUME); return !sc_ep_test(sc, SE_FL_WAIT_DATA | SE_FL_WONT_CONSUME);
@ -375,7 +371,7 @@ static inline int sc_is_send_allowed(const struct stconn *sc)
static inline int sc_rcv_may_expire(const struct stconn *sc) static inline int sc_rcv_may_expire(const struct stconn *sc)
{ {
if ((chn_prod(sc_ic(sc))->flags & SC_FL_SHUTR) || if ((sc->flags & SC_FL_SHUTR) ||
(sc_ic(sc)->flags & (CF_READ_TIMEOUT|CF_READ_EVENT))) (sc_ic(sc)->flags & (CF_READ_TIMEOUT|CF_READ_EVENT)))
return 0; return 0;
if (sc->flags & (SC_FL_EOI|SC_FL_WONT_READ|SC_FL_NEED_BUFF|SC_FL_NEED_ROOM)) if (sc->flags & (SC_FL_EOI|SC_FL_WONT_READ|SC_FL_NEED_BUFF|SC_FL_NEED_ROOM))
@ -387,7 +383,7 @@ static inline int sc_rcv_may_expire(const struct stconn *sc)
static inline int sc_snd_may_expire(const struct stconn *sc) static inline int sc_snd_may_expire(const struct stconn *sc)
{ {
if ((chn_cons(sc_oc(sc))->flags & SC_FL_SHUTW) || if ((sc->flags & SC_FL_SHUTW) ||
(sc_oc(sc)->flags & (CF_WRITE_TIMEOUT|CF_WRITE_EVENT))) (sc_oc(sc)->flags & (CF_WRITE_TIMEOUT|CF_WRITE_EVENT)))
return 0; return 0;
if (sc_ep_test(sc, SE_FL_WONT_CONSUME)) if (sc_ep_test(sc, SE_FL_WONT_CONSUME))

View File

@ -625,7 +625,7 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
int i, j, max; int i, j, max;
/* FIXME: Don't watch the other side ! */ /* FIXME: Don't watch the other side ! */
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
return 1; return 1;
chunk_reset(&trash); chunk_reset(&trash);
@ -889,7 +889,7 @@ static int cli_io_handler_show_tasks(struct appctx *appctx)
int i, max; int i, max;
/* FIXME: Don't watch the other side ! */ /* FIXME: Don't watch the other side ! */
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
return 1; return 1;
/* It's not possible to scan queues in small chunks and yield in the /* It's not possible to scan queues in small chunks and yield in the
@ -1030,7 +1030,7 @@ static int cli_io_handler_show_activity(struct appctx *appctx)
int thr; int thr;
/* FIXME: Don't watch the other side ! */ /* FIXME: Don't watch the other side ! */
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
return 1; return 1;
chunk_reset(&trash); chunk_reset(&trash);

View File

@ -471,7 +471,7 @@ struct task *task_run_applet(struct task *t, void *context, unsigned int state)
(b_size(sc_ib(sc)) && !b_data(sc_ib(sc)) && sc->flags & SC_FL_NEED_ROOM) || // asks for room in an empty buffer (b_size(sc_ib(sc)) && !b_data(sc_ib(sc)) && sc->flags & SC_FL_NEED_ROOM) || // asks for room in an empty buffer
(b_data(sc_ob(sc)) && sc_is_send_allowed(sc)) || // asks for data already present (b_data(sc_ob(sc)) && sc_is_send_allowed(sc)) || // asks for data already present
(!b_data(sc_ib(sc)) && b_data(sc_ob(sc)) && // didn't return anything ... (!b_data(sc_ib(sc)) && b_data(sc_ob(sc)) && // didn't return anything ...
(!(sc_oc(sc)->flags & CF_WRITE_EVENT) && (chn_cons(sc_oc(sc))->flags & SC_FL_SHUTW_NOW))))) { // ... and left data pending after a shut (!(sc_oc(sc)->flags & CF_WRITE_EVENT) && (sc->flags & SC_FL_SHUTW_NOW))))) { // ... and left data pending after a shut
rate = update_freq_ctr(&app->call_rate, 1); rate = update_freq_ctr(&app->call_rate, 1);
if (rate >= 100000 && app->call_rate.prev_ctr) // looped like this more than 100k times over last second if (rate >= 100000 && app->call_rate.prev_ctr) // looped like this more than 100k times over last second
stream_dump_and_crash(&app->obj_type, read_freq_ctr(&app->call_rate)); stream_dump_and_crash(&app->obj_type, read_freq_ctr(&app->call_rate));

View File

@ -1214,7 +1214,7 @@ static int cli_io_handler_show_env(struct appctx *appctx)
char **var = ctx->var; char **var = ctx->var;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
return 1; return 1;
chunk_reset(&trash); chunk_reset(&trash);
@ -1253,7 +1253,7 @@ static int cli_io_handler_show_fd(struct appctx *appctx)
int ret = 1; int ret = 1;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
goto end; goto end;
chunk_reset(&trash); chunk_reset(&trash);

View File

@ -314,7 +314,7 @@ static int cli_io_handler_show_threads(struct appctx *appctx)
int thr; int thr;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
return 1; return 1;
if (appctx->st0) if (appctx->st0)
@ -1162,7 +1162,7 @@ static int debug_iohandler_fd(struct appctx *appctx)
int i, fd; int i, fd;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
goto end; goto end;
chunk_reset(&trash); chunk_reset(&trash);
@ -1370,7 +1370,7 @@ static int debug_iohandler_memstats(struct appctx *appctx)
int ret = 1; int ret = 1;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
goto end; goto end;
if (!ctx->width) { if (!ctx->width) {

View File

@ -349,7 +349,7 @@ static int cli_io_handler_pat_list(struct appctx *appctx)
struct pat_ref_elt *elt; struct pat_ref_elt *elt;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) { if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW)) {
/* If we're forced to shut down, we might have to remove our /* If we're forced to shut down, we might have to remove our
* reference to the last ref_elt being dumped. * reference to the last ref_elt being dumped.
*/ */

View File

@ -568,7 +568,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
char *reloadtxt = NULL; char *reloadtxt = NULL;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
return 1; return 1;
if (up < 0) /* must never be negative because of clock drift */ if (up < 0) /* must never be negative because of clock drift */
@ -715,7 +715,7 @@ static int cli_io_handler_show_loadstatus(struct appctx *appctx)
return 1; return 1;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
return 1; return 1;
env = getenv("HAPROXY_LOAD_SUCCESS"); env = getenv("HAPROXY_LOAD_SUCCESS");

View File

@ -3209,7 +3209,7 @@ static int cli_io_handler_show_errors(struct appctx *appctx)
extern const char *monthname[12]; extern const char *monthname[12];
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
return 1; return 1;
chunk_reset(&trash); chunk_reset(&trash);

View File

@ -8262,7 +8262,7 @@ static int cli_io_handler_dump_quic(struct appctx *appctx)
goto done; goto done;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) { if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW)) {
/* If we're forced to shut down, we might have to remove our /* If we're forced to shut down, we might have to remove our
* reference to the last stream being dumped. * reference to the last stream being dumped.
*/ */

View File

@ -350,7 +350,7 @@ int cli_io_handler_show_ring(struct appctx *appctx)
int ret; int ret;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
return 1; return 1;
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
@ -423,7 +423,7 @@ int cli_io_handler_show_ring(struct appctx *appctx)
/* we've drained everything and are configured to wait for more /* we've drained everything and are configured to wait for more
* data or an event (keypress, close) * data or an event (keypress, close)
*/ */
if (!sc_oc(sc)->output && !(chn_cons(sc_oc(sc))->flags & SC_FL_SHUTW)) { if (!sc_oc(sc)->output && !(sc->flags & SC_FL_SHUTW)) {
/* let's be woken up once new data arrive */ /* let's be woken up once new data arrive */
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
LIST_APPEND(&ring->waiters, &appctx->wait_entry); LIST_APPEND(&ring->waiters, &appctx->wait_entry);

View File

@ -2149,7 +2149,7 @@ static int cli_io_handler_commit_cert(struct appctx *appctx)
struct ckch_inst *ckchi; struct ckch_inst *ckchi;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
goto end; goto end;
while (1) { while (1) {
@ -2826,7 +2826,7 @@ static int cli_io_handler_commit_cafile_crlfile(struct appctx *appctx)
char *path; char *path;
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
goto end; goto end;
/* The ctx was already validated by the ca-file/crl-file parsing /* The ctx was already validated by the ca-file/crl-file parsing

View File

@ -1117,7 +1117,7 @@ static int cli_io_handler_add_crtlist(struct appctx *appctx)
* created. * created.
*/ */
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW))
goto end; goto end;
switch (ctx->state) { switch (ctx->state) {

View File

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

View File

@ -5044,7 +5044,7 @@ static int cli_io_handler_table(struct appctx *appctx)
* data though. * data though.
*/ */
/* FIXME: Don't watch the other side !*/ /* FIXME: Don't watch the other side !*/
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) { if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW)) {
/* in case of abort, remove any refcount we might have set on an entry */ /* in case of abort, remove any refcount we might have set on an entry */
if (ctx->state == STATE_DUMP) { if (ctx->state == STATE_DUMP) {
stksess_kill_if_expired(ctx->t, ctx->entry, 1); stksess_kill_if_expired(ctx->t, ctx->entry, 1);

View File

@ -3599,7 +3599,8 @@ static int cli_io_handler_dump_sess(struct appctx *appctx)
goto done; goto done;
} }
if (unlikely(chn_cons(sc_ic(sc))->flags & SC_FL_SHUTW)) { /* FIXME: Don't watch the other side !*/
if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUTW)) {
/* If we're forced to shut down, we might have to remove our /* If we're forced to shut down, we might have to remove our
* reference to the last stream being dumped. * reference to the last stream being dumped.
*/ */