MINOR: stream-int: make appctx_new() take the applet in argument

Doing so simplifies the initialization of a new appctx. We don't
need appctx_set_applet() anymore.
This commit is contained in:
Willy Tarreau 2015-04-05 00:15:26 +02:00
parent 9903f0e1a2
commit a7513f5d00
2 changed files with 12 additions and 21 deletions

View File

@ -112,25 +112,19 @@ static inline void appctx_init(struct appctx *appctx)
appctx->st0 = appctx->st1 = appctx->st2 = 0;
}
/* sets <appctx>'s applet to point to <applet> */
static inline void appctx_set_applet(struct appctx *appctx, struct si_applet *applet)
{
appctx->applet = applet;
}
/* Tries to allocate a new appctx and initialize its main fields. The
* appctx is returned on success, NULL on failure. The appctx must be
* released using pool_free2(connection) or appctx_free(), since it's
* allocated from the connection pool.
/* Tries to allocate a new appctx and initialize its main fields. The appctx
* is returned on success, NULL on failure. The appctx must be released using
* pool_free2(connection) or appctx_free(), since it's allocated from the
* connection pool. <applet> is assigned as the applet, but it can be NULL.
*/
static inline struct appctx *appctx_new()
static inline struct appctx *appctx_new(struct si_applet *applet)
{
struct appctx *appctx;
appctx = pool_alloc2(pool2_connection);
if (likely(appctx != NULL)) {
appctx->obj_type = OBJ_TYPE_APPCTX;
appctx->applet = NULL;
appctx->applet = applet;
appctx_init(appctx);
}
return appctx;
@ -233,13 +227,11 @@ static inline int si_conn_ready(struct stream_interface *si)
}
/* Attach appctx <appctx> to the stream interface <si>. The stream interface
* is configured to work with an applet context. It is left to the caller to
* call appctx_set_applet() to assign an applet to this context.
* is configured to work with an applet context.
*/
static inline void si_attach_appctx(struct stream_interface *si, struct appctx *appctx)
{
si->ops = &si_embedded_ops;
appctx->obj_type = OBJ_TYPE_APPCTX;
si->end = &appctx->obj_type;
}
@ -322,15 +314,15 @@ static inline struct connection *si_alloc_conn(struct stream_interface *si, int
/* Release the interface's existing endpoint (connection or appctx) and
* allocate then initialize a new appctx which is assigned to the interface
* and returned. NULL may be returned upon memory shortage. It is left to the
* caller to call appctx_set_applet() to assign an applet to this context.
* and returned. NULL may be returned upon memory shortage. Applet <applet>
* is assigned to the appctx, but it may be NULL.
*/
static inline struct appctx *si_alloc_appctx(struct stream_interface *si)
static inline struct appctx *si_alloc_appctx(struct stream_interface *si, struct si_applet *applet)
{
struct appctx *appctx;
si_release_endpoint(si);
appctx = appctx_new();
appctx = appctx_new(applet);
if (appctx)
si_attach_appctx(si, appctx);

View File

@ -377,11 +377,10 @@ struct appctx *stream_int_register_handler(struct stream_interface *si, struct s
DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si_task(si));
appctx = si_alloc_appctx(si);
appctx = si_alloc_appctx(si, app);
if (!appctx)
return NULL;
appctx_set_applet(appctx, app);
si->flags |= SI_FL_WAIT_DATA;
return si_appctx(si);
}