From b36e512bd0527cbd3296527472ca852f5f96539f Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 17 Apr 2023 17:32:43 +0200 Subject: [PATCH] MINOR: stconn: Propagate EOS from an applet to the attached stream-connector In the same way than for a stream-connector attached to a mux, an EOS is now propagated from an applet to its stream-connector. To do so, sc_applet_eos() function is added. --- src/stconn.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/stconn.c b/src/stconn.c index bee5be14e..0cfc4a7e3 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -1821,6 +1821,37 @@ struct task *sc_conn_io_cb(struct task *t, void *ctx, unsigned int state) return t; } +/* + * This function propagates an end-of-stream received from an applet. It + * updates the stream connector. If it is is already shut, the applet is + * released. Otherwise, we try to forward the shutdown, immediately or ASAP. + */ +static void sc_applet_eos(struct stconn *sc) +{ + struct channel *ic = sc_ic(sc); + + BUG_ON(!sc_appctx(sc)); + + if (sc->flags & (SC_FL_EOS|SC_FL_ABRT_DONE)) + return; + sc->flags |= SC_FL_EOS; + ic->flags |= CF_READ_EVENT; + + /* Note: on abort, we don't call the applet */ + + if (!sc_state_in(sc->state, SC_SB_CON|SC_SB_RDY|SC_SB_EST)) + return; + + if (sc->flags & SC_FL_SHUT_DONE) { + appctx_shut(__sc_appctx(sc)); + sc->state = SC_ST_DIS; + if (sc->flags & SC_FL_ISBACK) + __sc_strm(sc)->conn_exp = TICK_ETERNITY; + } + else if (sc_cond_forward_shut(sc)) + return sc_app_shut_applet(sc); +} + /* Callback to be used by applet handlers upon completion. It updates the stream * (which may or may not take this opportunity to try to forward data), then * may re-enable the applet's based on the channels and stream connector's final @@ -1845,7 +1876,7 @@ static int sc_applet_process(struct stconn *sc) if (sc_ep_test(sc, SE_FL_EOS)) { /* we received a shutdown */ - sc_abort(sc); + sc_applet_eos(sc); } BUG_ON(sc_ep_test(sc, SE_FL_HAVE_NO_DATA|SE_FL_EOI) == SE_FL_EOI);