MINOR: applet: Use the CS to register and release applets instead of SI
si_register_applet() and si_applet_release() are renamed
cs_register_applet() and cs_applet_release() and now manipulate a
conn-stream instead of a stream-inteface.
diff --git a/include/haproxy/conn_stream.h b/include/haproxy/conn_stream.h
index 269d129..bb1601c 100644
--- a/include/haproxy/conn_stream.h
+++ b/include/haproxy/conn_stream.h
@@ -54,6 +54,9 @@
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 cdc1320..93fffff 100644
--- a/include/haproxy/stream_interface.h
+++ b/include/haproxy/stream_interface.h
@@ -41,7 +41,6 @@
/* 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 @@
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 8dc7d1a..8983e1d 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -2132,7 +2132,7 @@
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 ea3438e..3e725c7 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1816,7 +1816,7 @@
}
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 2589dc1..b6b7dfd 100644
--- a/src/conn_stream.c
+++ b/src/conn_stream.c
@@ -11,6 +11,7 @@
*/
#include <haproxy/api.h>
+#include <haproxy/applet.h>
#include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/pool.h>
@@ -283,8 +284,7 @@
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 @@
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 0a47f1b..8147cf3 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -423,7 +423,7 @@
*/
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 bf0895a..44ed445 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -1012,7 +1012,7 @@
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 7b94812..85e2b61 100644
--- a/src/stream_interface.c
+++ b/src/stream_interface.c
@@ -269,29 +269,6 @@
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 @@
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 @@
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: