MEDIUM: applet: make the applet not depend on a stream interface anymore
Now that applet's functions only take an appctx in argument, not a
stream interface. This slightly simplifies the code and will be needed
to take the appctx out of the stream interface.
diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h
index 5462131..ec52f1e 100644
--- a/include/proto/stream_interface.h
+++ b/include/proto/stream_interface.h
@@ -179,7 +179,7 @@
}
else if ((appctx = objt_appctx(si->end))) {
if (appctx->applet->release)
- appctx->applet->release(si);
+ appctx->applet->release(appctx);
appctx_free(appctx); /* we share the connection pool */
}
si->end = NULL;
@@ -243,27 +243,16 @@
return objt_appctx(si->end);
}
-/* returns a pointer to the applet being run in the SI or NULL if none */
-static inline const struct si_applet *si_applet(struct stream_interface *si)
-{
- const struct appctx *appctx;
-
- appctx = si_appctx(si);
- if (appctx)
- return appctx->applet;
- return NULL;
-}
-
/* Call the applet's main function when an appctx is attached to the stream
* interface. Returns zero if no call was made, or non-zero if a call was made.
*/
static inline int si_applet_call(struct stream_interface *si)
{
- const struct si_applet *applet;
+ struct appctx *appctx;
- applet = si_applet(si);
- if (applet) {
- applet->fct(si);
+ appctx = si_appctx(si);
+ if (appctx) {
+ appctx->applet->fct(appctx);
return 1;
}
return 0;
@@ -272,11 +261,11 @@
/* call the applet's release function if any. Needs to be called upon close() */
static inline void si_applet_release(struct stream_interface *si)
{
- const struct si_applet *applet;
+ struct appctx *appctx;
- applet = si_applet(si);
- if (applet && applet->release)
- applet->release(si);
+ appctx = si_appctx(si);
+ if (appctx && appctx->applet->release)
+ appctx->applet->release(appctx);
}
/* Try to allocate a new connection and assign it to the interface. If
diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h
index 72835fa..7e688cf 100644
--- a/include/types/stream_interface.h
+++ b/include/types/stream_interface.h
@@ -103,13 +103,15 @@
int conn_retries; /* number of connect retries left */
};
+struct appctx;
+
/* An applet designed to run in a stream interface */
struct si_applet {
enum obj_type obj_type; /* object type = OBJ_TYPE_APPLET */
/* 3 unused bytes here */
char *name; /* applet's name to report in logs */
- void (*fct)(struct stream_interface *); /* internal I/O handler, may never be NULL */
- void (*release)(struct stream_interface *); /* callback to release resources, may be NULL */
+ void (*fct)(struct appctx *); /* internal I/O handler, may never be NULL */
+ void (*release)(struct appctx *); /* callback to release resources, may be NULL */
};
/* operations available on a stream-interface */
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 095371f..4375bec 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -133,7 +133,7 @@
static int stats_pats_list(struct stream_interface *si);
static int stats_pat_list(struct stream_interface *si);
static int stats_map_lookup(struct stream_interface *si);
-static void cli_release_handler(struct stream_interface *si);
+static void cli_release_handler(struct appctx *appctx);
/*
* cli_io_handler()
@@ -2217,9 +2217,9 @@
* STAT_CLI_* constants. appctx->st1 is used to indicate whether prompt is enabled
* or not.
*/
-static void cli_io_handler(struct stream_interface *si)
+static void cli_io_handler(struct appctx *appctx)
{
- struct appctx *appctx = __objt_appctx(si->end);
+ struct stream_interface *si = appctx->owner;
struct channel *req = si_oc(si);
struct channel *res = si_ic(si);
int reql;
@@ -2315,7 +2315,7 @@
}
else { /* output functions: first check if the output buffer is closed then abort */
if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) {
- cli_release_handler(si);
+ cli_release_handler(appctx);
appctx->st0 = STAT_CLI_END;
continue;
}
@@ -2373,7 +2373,7 @@
appctx->st0 = STAT_CLI_PROMPT;
break;
default: /* abnormal state */
- cli_release_handler(si);
+ cli_release_handler(appctx);
appctx->st0 = STAT_CLI_PROMPT;
break;
}
@@ -4854,9 +4854,9 @@
* appctx->st0 contains the operation in progress (dump, done). The handler
* automatically unregisters itself once transfer is complete.
*/
-static void http_stats_io_handler(struct stream_interface *si)
+static void http_stats_io_handler(struct appctx *appctx)
{
- struct appctx *appctx = __objt_appctx(si->end);
+ struct stream_interface *si = appctx->owner;
struct stream *s = si_strm(si);
struct channel *req = si_oc(si);
struct channel *res = si_ic(si);
@@ -5799,10 +5799,8 @@
* external abort, we won't call the i/o handler anymore so we may need to
* remove back references to the stream currently being dumped.
*/
-static void cli_release_handler(struct stream_interface *si)
+static void cli_release_handler(struct appctx *appctx)
{
- struct appctx *appctx = __objt_appctx(si->end);
-
if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) {
if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users))
LIST_DEL(&appctx->ctx.sess.bref.users);
diff --git a/src/hlua.c b/src/hlua.c
index 702ba40..d1531be 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -1429,9 +1429,9 @@
* connection. It is used for notify space avalaible to send or data
* received.
*/
-static void hlua_socket_handler(struct stream_interface *si)
+static void hlua_socket_handler(struct appctx *appctx)
{
- struct appctx *appctx = objt_appctx(si->end);
+ struct stream_interface *si = appctx->owner;
struct connection *c = objt_conn(si_opposite(si)->end);
/* Wakeup the main stream if the client connection is closed. */
@@ -1467,10 +1467,8 @@
* Remove the link from the object to this stream.
* Wake all the pending signals.
*/
-static void hlua_socket_release(struct stream_interface *si)
+static void hlua_socket_release(struct appctx *appctx)
{
- struct appctx *appctx = objt_appctx(si->end);
-
/* Remove my link in the original object. */
if (appctx->ctx.hlua.socket)
appctx->ctx.hlua.socket->s = NULL;
diff --git a/src/peers.c b/src/peers.c
index 0676120..6af565f 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -178,10 +178,10 @@
/*
* Callback to release a session with a peer
*/
-static void peer_session_release(struct stream_interface *si)
+static void peer_session_release(struct appctx *appctx)
{
+ struct stream_interface *si = appctx->owner;
struct stream *s = si_strm(si);
- struct appctx *appctx = objt_appctx(si->end);
struct peer_session *ps = (struct peer_session *)appctx->ctx.peers.ptr;
/* appctx->ctx.peers.ptr is not a peer session */
@@ -212,11 +212,11 @@
/*
* IO Handler to handle message exchance with a peer
*/
-static void peer_io_handler(struct stream_interface *si)
+static void peer_io_handler(struct appctx *appctx)
{
+ struct stream_interface *si = appctx->owner;
struct stream *s = si_strm(si);
struct peers *curpeers = (struct peers *)strm_fe(s)->parent;
- struct appctx *appctx = objt_appctx(si->end);
int reql = 0;
int repl = 0;
@@ -1066,7 +1066,6 @@
*/
static void peer_session_forceshutdown(struct stream * stream)
{
- struct stream_interface *oldsi = NULL;
struct appctx *appctx = NULL;
int i;
@@ -1076,8 +1075,6 @@
continue;
if (appctx->applet != &peer_applet)
continue;
-
- oldsi = &stream->si[i];
break;
}
@@ -1085,7 +1082,7 @@
return;
/* call release to reinit resync states if needed */
- peer_session_release(oldsi);
+ peer_session_release(appctx);
appctx->st0 = PEER_SESS_ST_END;
appctx->ctx.peers.ptr = NULL;
task_wakeup(stream->task, TASK_WOKEN_MSG);