]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: applet: make the applet not depend on a stream interface anymore
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Apr 2015 10:05:19 +0000 (12:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 23 Apr 2015 15:56:16 +0000 (17:56 +0200)
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.

include/proto/stream_interface.h
include/types/stream_interface.h
src/dumpstats.c
src/hlua.c
src/peers.c

index 5462131f1363cd9a2ae14433eb6f00f48218e7f5..ec52f1e60e78b9b100e6dc345d02e070665a7bb1 100644 (file)
@@ -179,7 +179,7 @@ static inline void si_release_endpoint(struct stream_interface *si)
        }
        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 @@ static inline struct appctx *si_appctx(struct stream_interface *si)
        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 @@ static inline int si_applet_call(struct stream_interface *si)
 /* 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
index 72835faad172f8a8caad5f9e3d8692fd7742fa01..7e688cfecae43edba622ff5ccc0269eb07d8302c 100644 (file)
@@ -103,13 +103,15 @@ struct stream_interface {
        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 */
index 095371fd4ae35f69035f6c3bc57829ae12df333f..4375bec71320f85c27dd27ae639c2891becfb4fe 100644 (file)
@@ -133,7 +133,7 @@ static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_aut
 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 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
  * 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 @@ static void cli_io_handler(struct stream_interface *si)
                }
                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 @@ static void cli_io_handler(struct stream_interface *si)
                                        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 @@ static int stats_send_http_redirect(struct stream_interface *si)
  * 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 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si)
  * 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);
index 702ba4093b8652e7e2ca57c56e2c3823257a4967..d1531bef006f87eaf3f728ebeb39eb575ff468f3 100644 (file)
@@ -1429,9 +1429,9 @@ __LJMP static struct hlua_socket *hlua_checksocket(lua_State *L, int ud)
  * 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 @@ static void hlua_socket_handler(struct stream_interface *si)
  * 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;
index 0676120825e3cf87726bea1c2344c8cf4cc2799d..6af565fa7ea032d2986f1b0cb5cb55a7333f83a3 100644 (file)
@@ -178,10 +178,10 @@ static int peer_prepare_datamsg(struct stksess *ts, struct peer_session *ps, cha
 /*
  * 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 @@ static void peer_session_release(struct stream_interface *si)
 /*
  * 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 struct si_applet peer_applet = {
  */
 static void peer_session_forceshutdown(struct stream * stream)
 {
-       struct stream_interface *oldsi = NULL;
        struct appctx *appctx = NULL;
        int i;
 
@@ -1076,8 +1075,6 @@ static void peer_session_forceshutdown(struct stream * stream)
                        continue;
                if (appctx->applet != &peer_applet)
                        continue;
-
-               oldsi = &stream->si[i];
                break;
        }
 
@@ -1085,7 +1082,7 @@ static void peer_session_forceshutdown(struct stream * stream)
                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);