MEDIUM: stconn: Explicitly pass shut modes to shut applet endpoints

It is the same than the previous patch but for applets. Here there is
already only one function. But with this patch, appctx_shut() function was
modified to explicitly get shutdown mode as parameter. In addition
appctx_shutw() was removed.
This commit is contained in:
Christopher Faulet 2024-04-16 18:07:43 +02:00
parent c96a873ba3
commit 4b80442832
3 changed files with 23 additions and 24 deletions

View File

@ -42,7 +42,7 @@ struct task *task_process_applet(struct task *t, void *context, unsigned int sta
int appctx_buf_available(void *arg); int appctx_buf_available(void *arg);
void *applet_reserve_svcctx(struct appctx *appctx, size_t size); void *applet_reserve_svcctx(struct appctx *appctx, size_t size);
void applet_reset_svcctx(struct appctx *appctx); void applet_reset_svcctx(struct appctx *appctx);
void appctx_shut(struct appctx *appctx); void appctx_shut(struct appctx *appctx, enum se_shut_mode mode);
struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, int thr); struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, int thr);
int appctx_finalize_startup(struct appctx *appctx, struct proxy *px, struct buffer *input); int appctx_finalize_startup(struct appctx *appctx, struct proxy *px, struct buffer *input);
@ -133,14 +133,6 @@ static inline void __appctx_free(struct appctx *appctx)
_HA_ATOMIC_DEC(&nb_applets); _HA_ATOMIC_DEC(&nb_applets);
} }
static inline void appctx_shutw(struct appctx *appctx)
{
if (se_fl_test(appctx->sedesc, SE_FL_SHW))
return;
se_fl_set(appctx->sedesc, SE_FL_SHWN);
}
/* wakes up an applet when conditions have changed. We're using a macro here in /* wakes up an applet when conditions have changed. We're using a macro here in
* order to retrieve the caller's place. * order to retrieve the caller's place.
*/ */

View File

@ -391,23 +391,30 @@ void applet_reset_svcctx(struct appctx *appctx)
appctx->svcctx = NULL; appctx->svcctx = NULL;
} }
/* call the applet's release() function if any, and marks the sedesc as shut. /* call the applet's release() function if any, and marks the sedesc as shut
* Needs to be called upon close(). * once both read and write side are shut. Needs to be called upon close().
*/ */
void appctx_shut(struct appctx *appctx) void appctx_shut(struct appctx *appctx, enum se_shut_mode mode)
{ {
if (applet_fl_test(appctx, APPCTX_FL_SHUTDOWN)) if (applet_fl_test(appctx, APPCTX_FL_SHUTDOWN))
return; return;
TRACE_ENTER(APPLET_EV_RELEASE, appctx); TRACE_ENTER(APPLET_EV_RELEASE, appctx);
if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !se_fl_test(appctx->sedesc, SE_FL_SHW))
se_fl_set(appctx->sedesc, SE_FL_SHWN);
if ((mode & (SE_SHR_RESET|SE_SHR_DRAIN)) && !se_fl_test(appctx->sedesc, SE_FL_SHR))
se_fl_set(appctx->sedesc, SE_FL_SHRR);
if (se_fl_test(appctx->sedesc, SE_FL_SHR) && se_fl_test(appctx->sedesc, SE_FL_SHW)) {
if (appctx->applet->release) if (appctx->applet->release)
appctx->applet->release(appctx); appctx->applet->release(appctx);
applet_fl_set(appctx, APPCTX_FL_SHUTDOWN); applet_fl_set(appctx, APPCTX_FL_SHUTDOWN);
if (LIST_INLIST(&appctx->buffer_wait.list)) if (LIST_INLIST(&appctx->buffer_wait.list))
LIST_DEL_INIT(&appctx->buffer_wait.list); LIST_DEL_INIT(&appctx->buffer_wait.list);
}
se_fl_set(appctx->sedesc, SE_FL_SHRR | SE_FL_SHWN);
TRACE_LEAVE(APPLET_EV_RELEASE, appctx); TRACE_LEAVE(APPLET_EV_RELEASE, appctx);
} }

View File

@ -405,7 +405,7 @@ static void sc_detach_endp(struct stconn **scp)
sc_ep_set(sc, SE_FL_ORPHAN); sc_ep_set(sc, SE_FL_ORPHAN);
sc->sedesc->sc = NULL; sc->sedesc->sc = NULL;
sc->sedesc = NULL; sc->sedesc = NULL;
appctx_shut(appctx); appctx_shut(appctx, SE_SHR_RESET|SE_SHW_NORMAL);
appctx_free(appctx); appctx_free(appctx);
} }
@ -884,7 +884,7 @@ static void sc_app_abort_applet(struct stconn *sc)
return; return;
if (sc->flags & SC_FL_SHUT_DONE) { if (sc->flags & SC_FL_SHUT_DONE) {
appctx_shut(__sc_appctx(sc)); appctx_shut(__sc_appctx(sc), SE_SHR_RESET|SE_SHW_NORMAL);
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;
@ -929,11 +929,11 @@ static void sc_app_shut_applet(struct stconn *sc)
*/ */
if (!(sc->flags & (SC_FL_ERROR|SC_FL_NOLINGER|SC_FL_EOS|SC_FL_ABRT_DONE)) && if (!(sc->flags & (SC_FL_ERROR|SC_FL_NOLINGER|SC_FL_EOS|SC_FL_ABRT_DONE)) &&
!(ic->flags & CF_DONT_READ)) { !(ic->flags & CF_DONT_READ)) {
appctx_shutw(__sc_appctx(sc)); appctx_shut(__sc_appctx(sc), SE_SHW_NORMAL);
return; return;
} }
appctx_shut(__sc_appctx(sc)); appctx_shut(__sc_appctx(sc), SE_SHR_RESET|SE_SHW_NORMAL);
sc->state = SC_ST_DIS; sc->state = SC_ST_DIS;
break; break;
@ -942,7 +942,7 @@ static void sc_app_shut_applet(struct stconn *sc)
case SC_ST_QUE: case SC_ST_QUE:
case SC_ST_TAR: case SC_ST_TAR:
/* Note that none of these states may happen with applets */ /* Note that none of these states may happen with applets */
appctx_shut(__sc_appctx(sc)); appctx_shut(__sc_appctx(sc), SE_SHR_RESET|SE_SHW_NORMAL);
sc->state = SC_ST_DIS; sc->state = SC_ST_DIS;
break; break;
default: default:
@ -1866,7 +1866,7 @@ static void sc_applet_eos(struct stconn *sc)
return; return;
if (sc->flags & SC_FL_SHUT_DONE) { if (sc->flags & SC_FL_SHUT_DONE) {
appctx_shut(__sc_appctx(sc)); appctx_shut(__sc_appctx(sc), SE_SHR_RESET|SE_SHW_NORMAL);
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;