diff --git a/include/haproxy/conn_stream.h b/include/haproxy/conn_stream.h index 269d129f5..bb1601ceb 100644 --- a/include/haproxy/conn_stream.h +++ b/include/haproxy/conn_stream.h @@ -54,6 +54,9 @@ int cs_reset_endp(struct conn_stream *cs); void cs_detach_endp(struct conn_stream *cs); void cs_detach_app(struct conn_stream *cs); +struct appctx *cs_register_applet(struct conn_stream *cs, struct applet *app); +void cs_applet_release(struct conn_stream *cs); + /* Returns the endpoint target without any control */ static inline void *__cs_endp_target(const struct conn_stream *cs) { diff --git a/include/haproxy/stream_interface.h b/include/haproxy/stream_interface.h index cdc13200a..93fffff92 100644 --- a/include/haproxy/stream_interface.h +++ b/include/haproxy/stream_interface.h @@ -41,7 +41,6 @@ void si_free(struct stream_interface *si); /* main event functions used to move data between sockets and buffers */ int conn_si_send_proxy(struct connection *conn, unsigned int flag); -struct appctx *si_register_handler(struct stream_interface *si, struct applet *app); void si_applet_wake_cb(struct stream_interface *si); void si_update_rx(struct stream_interface *si); void si_update_tx(struct stream_interface *si); @@ -110,16 +109,6 @@ static inline int si_init(struct stream_interface *si) return 0; } -/* call the applet's release function if any. Needs to be called upon close() */ -static inline void si_applet_release(struct stream_interface *si) -{ - struct appctx *appctx; - - appctx = __cs_appctx(si->cs); - if (appctx->applet->release && !cs_state_in(si->cs->state, CS_SB_DIS|CS_SB_CLO)) - appctx->applet->release(appctx); -} - /* Returns non-zero if the stream interface's Rx path is blocked */ static inline int si_rx_blocked(const struct stream_interface *si) { diff --git a/src/backend.c b/src/backend.c index 8dc7d1a33..8983e1d01 100644 --- a/src/backend.c +++ b/src/backend.c @@ -2132,7 +2132,7 @@ void back_handle_st_req(struct stream *s) struct appctx *appctx = cs_appctx(s->csb); if (!appctx || appctx->applet != __objt_applet(s->target)) - appctx = si_register_handler(cs->si, objt_applet(s->target)); + appctx = cs_register_applet(cs, objt_applet(s->target)); if (!appctx) { /* No more memory, let's immediately abort. Force the diff --git a/src/cache.c b/src/cache.c index ea3438e5e..3e725c719 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1816,7 +1816,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p } s->target = &http_cache_applet.obj_type; - if ((appctx = si_register_handler(cs_si(s->csb), objt_applet(s->target)))) { + if ((appctx = cs_register_applet(s->csb, objt_applet(s->target)))) { appctx->st0 = HTX_CACHE_INIT; appctx->rule = rule; appctx->ctx.cache.entry = res; diff --git a/src/conn_stream.c b/src/conn_stream.c index 2589dc148..b6b7dfded 100644 --- a/src/conn_stream.c +++ b/src/conn_stream.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -283,8 +284,7 @@ void cs_detach_endp(struct conn_stream *cs) struct appctx *appctx = cs_appctx(cs); cs->endp->flags |= CS_EP_ORPHAN; - if (cs->si) - si_applet_release(cs->si); + cs_applet_release(cs); appctx_free(appctx); cs->endp = NULL; } @@ -354,3 +354,36 @@ int cs_reset_endp(struct conn_stream *cs) cs->endp->flags |= CS_EP_DETACHED; return 0; } + + +/* Register an applet to handle a conn-stream as a new appctx. The CS will + * wake it up every time it is solicited. The appctx must be deleted by the task + * handler using cs_detach_endp(), possibly from within the function itself. + * It also pre-initializes the applet's context and returns it (or NULL in case + * it could not be allocated). + */ +struct appctx *cs_register_applet(struct conn_stream *cs, struct applet *app) +{ + struct appctx *appctx; + + DPRINTF(stderr, "registering handler %p for cs %p (was %p)\n", app, cs, cs_strm_task(cs)); + + appctx = appctx_new(app, cs->endp); + if (!appctx) + return NULL; + cs_attach_applet(cs, appctx, appctx); + appctx->owner = cs; + appctx->t->nice = __cs_strm(cs)->task->nice; + si_cant_get(cs->si); + appctx_wakeup(appctx); + return appctx; +} + +/* call the applet's release function if any. Needs to be called upon close() */ +void cs_applet_release(struct conn_stream *cs) +{ + struct appctx *appctx = __cs_appctx(cs); + + if (appctx->applet->release && !cs_state_in(cs->state, CS_SB_DIS|CS_SB_CLO)) + appctx->applet->release(appctx); +} diff --git a/src/http_ana.c b/src/http_ana.c index 0a47f1b2e..8147cf351 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -423,7 +423,7 @@ int http_process_req_common(struct stream *s, struct channel *req, int an_bit, s */ if (!s->target && http_stats_check_uri(s, txn, px)) { s->target = &http_stats_applet.obj_type; - if (unlikely(!si_register_handler(cs_si(s->csb), objt_applet(s->target)))) { + if (unlikely(!cs_register_applet(s->csb, objt_applet(s->target)))) { s->logs.tv_request = now; if (!(s->flags & SF_ERR_MASK)) s->flags |= SF_ERR_RESOURCE; diff --git a/src/stream.c b/src/stream.c index bf0895a67..44ed445ef 100644 --- a/src/stream.c +++ b/src/stream.c @@ -1012,7 +1012,7 @@ enum act_return process_use_service(struct act_rule *rule, struct proxy *px, if (flags & ACT_OPT_FIRST) { /* Register applet. this function schedules the applet. */ s->target = &rule->applet.obj_type; - appctx = si_register_handler(cs_si(s->csb), objt_applet(s->target)); + appctx = cs_register_applet(s->csb, objt_applet(s->target)); if (unlikely(!appctx)) return ACT_RET_ERR; diff --git a/src/stream_interface.c b/src/stream_interface.c index 7b9481267..85e2b6190 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -269,29 +269,6 @@ static void cs_app_chk_snd(struct conn_stream *cs) task_wakeup(cs_strm_task(cs), TASK_WOKEN_IO); } -/* Register an applet to handle a stream_interface as a new appctx. The SI will - * wake it up every time it is solicited. The appctx must be deleted by the task - * handler using si_release_endpoint(), possibly from within the function itself. - * It also pre-initializes the applet's context and returns it (or NULL in case - * it could not be allocated). - */ -struct appctx *si_register_handler(struct stream_interface *si, struct applet *app) -{ - struct appctx *appctx; - - DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si_task(si)); - - appctx = appctx_new(app, si->cs->endp); - if (!appctx) - return NULL; - cs_attach_applet(si->cs, appctx, appctx); - appctx->owner = si->cs; - appctx->t->nice = si_strm(si)->task->nice; - si_cant_get(si); - appctx_wakeup(appctx); - return appctx; -} - /* This callback is used to send a valid PROXY protocol line to a socket being * established. It returns 0 if it fails in a fatal way or needs to poll to go * further, otherwise it returns non-zero and removes itself from the connection's @@ -1655,7 +1632,7 @@ static void cs_app_shutr_applet(struct conn_stream *cs) return; if (cs_oc(cs)->flags & CF_SHUTW) { - si_applet_release(cs->si); + cs_applet_release(cs); cs->state = CS_ST_DIS; __cs_strm(cs)->conn_exp = TICK_ETERNITY; } @@ -1713,7 +1690,7 @@ static void cs_app_shutw_applet(struct conn_stream *cs) case CS_ST_QUE: case CS_ST_TAR: /* Note that none of these states may happen with applets */ - si_applet_release(cs->si); + cs_applet_release(cs); cs->state = CS_ST_DIS; /* fall through */ default: