MINOR: conn_stream: add a pointer back to the cs from the endpoint

Muxes and applets need to have both a pointer to the endpoint and to the
conn_stream. It would seem more natural that they only have a pointer to
the endpoint (that is always there) and that this one has an optional
pointer to the conn_stream. This would reduce the number of elements to
manipulate in lower level code. In addition, the conn_stream is not much
used from the lower layers (wake and exceptional events mostly).
This commit is contained in:
Willy Tarreau 2022-05-10 09:04:18 +02:00
parent 66435e5f63
commit efb4618c6e
2 changed files with 10 additions and 3 deletions

View File

@ -158,11 +158,13 @@ struct data_cb {
* *
* <target> is the mux or the appctx * <target> is the mux or the appctx
* <ctx> is the context set and used by <target> * <ctx> is the context set and used by <target>
* <cs> is the conn_stream we're attached to, or NULL
* <flags> CS_EP_* * <flags> CS_EP_*
*/ */
struct cs_endpoint { struct cs_endpoint {
void *target; void *target;
void *ctx; void *ctx;
struct conn_stream *cs;
unsigned int flags; unsigned int flags;
}; };

View File

@ -86,6 +86,7 @@ void cs_endpoint_init(struct cs_endpoint *endp)
{ {
endp->target = NULL; endp->target = NULL;
endp->ctx = NULL; endp->ctx = NULL;
endp->cs = NULL;
endp->flags = CS_EP_NONE; endp->flags = CS_EP_NONE;
} }
@ -112,7 +113,7 @@ void cs_endpoint_free(struct cs_endpoint *endp)
/* Tries to allocate a new conn_stream and initialize its main fields. On /* Tries to allocate a new conn_stream and initialize its main fields. On
* failure, nothing is allocated and NULL is returned. It is an internal * failure, nothing is allocated and NULL is returned. It is an internal
* function. The caller must, at least, set the CS_EP_ORPHAN or CS_EP_DETAC§HED * function. The caller must, at least, set the CS_EP_ORPHAN or CS_EP_DETACHED
* flag. * flag.
*/ */
static struct conn_stream *cs_new(struct cs_endpoint *endp) static struct conn_stream *cs_new(struct cs_endpoint *endp)
@ -142,6 +143,7 @@ static struct conn_stream *cs_new(struct cs_endpoint *endp)
goto alloc_error; goto alloc_error;
} }
cs->endp = endp; cs->endp = endp;
endp->cs = cs;
return cs; return cs;
@ -364,9 +366,10 @@ static void cs_detach_endp(struct conn_stream **csp)
if (conn->mux) { if (conn->mux) {
/* TODO: handle unsubscribe for healthchecks too */ /* TODO: handle unsubscribe for healthchecks too */
cs->endp->flags |= CS_EP_ORPHAN;
if (cs->wait_event.events != 0) if (cs->wait_event.events != 0)
conn->mux->unsubscribe(cs, cs->wait_event.events, &cs->wait_event); conn->mux->unsubscribe(cs, cs->wait_event.events, &cs->wait_event);
cs->endp->flags |= CS_EP_ORPHAN;
cs->endp->cs = NULL;
conn->mux->detach(cs); conn->mux->detach(cs);
cs->endp = NULL; cs->endp = NULL;
} }
@ -384,8 +387,9 @@ static void cs_detach_endp(struct conn_stream **csp)
else if (cs->endp->flags & CS_EP_T_APPLET) { else if (cs->endp->flags & CS_EP_T_APPLET) {
struct appctx *appctx = __cs_appctx(cs); struct appctx *appctx = __cs_appctx(cs);
cs->endp->flags |= CS_EP_ORPHAN;
cs_applet_shut(cs); cs_applet_shut(cs);
cs->endp->flags |= CS_EP_ORPHAN;
cs->endp->cs = NULL;
appctx_free(appctx); appctx_free(appctx);
cs->endp = NULL; cs->endp = NULL;
} }
@ -478,6 +482,7 @@ int cs_reset_endp(struct conn_stream *cs)
cs_detach_endp(&cs); cs_detach_endp(&cs);
BUG_ON(cs->endp); BUG_ON(cs->endp);
cs->endp = new_endp; cs->endp = new_endp;
cs->endp->cs = cs;
cs->endp->flags |= CS_EP_DETACHED; cs->endp->flags |= CS_EP_DETACHED;
return 0; return 0;
} }