mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
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:
parent
9903f0e1a2
commit
a7513f5d00
@ -112,25 +112,19 @@ static inline void appctx_init(struct appctx *appctx)
|
|||||||
appctx->st0 = appctx->st1 = appctx->st2 = 0;
|
appctx->st0 = appctx->st1 = appctx->st2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sets <appctx>'s applet to point to <applet> */
|
/* Tries to allocate a new appctx and initialize its main fields. The appctx
|
||||||
static inline void appctx_set_applet(struct appctx *appctx, struct si_applet *applet)
|
* 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
|
||||||
appctx->applet = applet;
|
* connection pool. <applet> is assigned as the applet, but it can be NULL.
|
||||||
}
|
|
||||||
|
|
||||||
/* 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.
|
|
||||||
*/
|
*/
|
||||||
static inline struct appctx *appctx_new()
|
static inline struct appctx *appctx_new(struct si_applet *applet)
|
||||||
{
|
{
|
||||||
struct appctx *appctx;
|
struct appctx *appctx;
|
||||||
|
|
||||||
appctx = pool_alloc2(pool2_connection);
|
appctx = pool_alloc2(pool2_connection);
|
||||||
if (likely(appctx != NULL)) {
|
if (likely(appctx != NULL)) {
|
||||||
appctx->obj_type = OBJ_TYPE_APPCTX;
|
appctx->obj_type = OBJ_TYPE_APPCTX;
|
||||||
appctx->applet = NULL;
|
appctx->applet = applet;
|
||||||
appctx_init(appctx);
|
appctx_init(appctx);
|
||||||
}
|
}
|
||||||
return 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
|
/* 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
|
* is configured to work with an applet context.
|
||||||
* call appctx_set_applet() to assign an applet to this context.
|
|
||||||
*/
|
*/
|
||||||
static inline void si_attach_appctx(struct stream_interface *si, struct appctx *appctx)
|
static inline void si_attach_appctx(struct stream_interface *si, struct appctx *appctx)
|
||||||
{
|
{
|
||||||
si->ops = &si_embedded_ops;
|
si->ops = &si_embedded_ops;
|
||||||
appctx->obj_type = OBJ_TYPE_APPCTX;
|
|
||||||
si->end = &appctx->obj_type;
|
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
|
/* Release the interface's existing endpoint (connection or appctx) and
|
||||||
* allocate then initialize a new appctx which is assigned to the interface
|
* 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
|
* and returned. NULL may be returned upon memory shortage. Applet <applet>
|
||||||
* caller to call appctx_set_applet() to assign an applet to this context.
|
* 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;
|
struct appctx *appctx;
|
||||||
|
|
||||||
si_release_endpoint(si);
|
si_release_endpoint(si);
|
||||||
appctx = appctx_new();
|
appctx = appctx_new(applet);
|
||||||
if (appctx)
|
if (appctx)
|
||||||
si_attach_appctx(si, appctx);
|
si_attach_appctx(si, appctx);
|
||||||
|
|
||||||
|
@ -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));
|
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)
|
if (!appctx)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
appctx_set_applet(appctx, app);
|
|
||||||
si->flags |= SI_FL_WAIT_DATA;
|
si->flags |= SI_FL_WAIT_DATA;
|
||||||
return si_appctx(si);
|
return si_appctx(si);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user