int cs_attach_mux(struct conn_stream *cs, void *target, void *ctx);
int cs_attach_strm(struct conn_stream *cs, struct stream *strm);
+void cs_destroy(struct conn_stream *cs);
int cs_reset_endp(struct conn_stream *cs);
-void cs_detach_endp(struct conn_stream *cs);
-void cs_detach_app(struct conn_stream *cs);
struct appctx *cs_applet_create(struct conn_stream *cs, struct applet *app);
void cs_applet_shut(struct conn_stream *cs);
pool_free(pool_head_connstream, cs);
}
-/* Conditionally removes a conn-stream if it is detached and it there is no app
- * layer defined. Except on error path, this one must be used.
+/* Conditionally removes a conn-stream if it is detached and if there is no app
+ * layer defined. Except on error path, this one must be used. if release, the
+ * pointer on the CS is set to NULL.
*/
-static void cs_free_cond(struct conn_stream *cs)
+static void cs_free_cond(struct conn_stream **csp)
{
- if (!cs->app && (!cs->endp || (cs->endp->flags & CS_EP_DETACHED)))
+ struct conn_stream *cs = *csp;
+
+ if (!cs->app && (!cs->endp || (cs->endp->flags & CS_EP_DETACHED))) {
cs_free(cs);
+ *csp = NULL;
+ }
}
* endpoint is reset and flag as detached. If the app layer is also detached,
* the conn-stream is released.
*/
-void cs_detach_endp(struct conn_stream *cs)
+static void cs_detach_endp(struct conn_stream **csp)
{
+ struct conn_stream *cs = *csp;
+
+ if (!cs)
+ return;
+
if (!cs->endp)
goto reset_cs;
if (cs_strm(cs))
cs->ops = &cs_app_embedded_ops;
cs->data_cb = NULL;
- cs_free_cond(cs);
+ cs_free_cond(csp);
}
/* Detaches the conn_stream from the app layer. If there is no endpoint attached
* to the conn_stream
*/
-void cs_detach_app(struct conn_stream *cs)
+static void cs_detach_app(struct conn_stream **csp)
{
+ struct conn_stream *cs = *csp;
+
+ if (!cs)
+ return;
+
cs->app = NULL;
cs->data_cb = NULL;
sockaddr_free(&cs->src);
tasklet_free(cs->wait_event.tasklet);
cs->wait_event.tasklet = NULL;
cs->wait_event.events = 0;
- cs_free_cond(cs);
+ cs_free_cond(csp);
+}
+
+/* Destroy the conn_stream. It is detached from its endpoint and its
+ * application. After this call, the conn_stream must be considered as released.
+ */
+void cs_destroy(struct conn_stream *cs)
+{
+ cs_detach_endp(&cs);
+ cs_detach_app(&cs);
+ BUG_ON_HOT(cs);
}
/* Resets the conn-stream endpoint. It happens when the app layer want to renew
if (!__cs_endp_target(cs)) {
/* endpoint not attached or attached to a mux with no
* target. Thus the endpoint will not be release but just
- * reset
+ * reset. The app is still attached, the cs will not be
+ * released.
*/
- cs_detach_endp(cs);
+ cs_detach_endp(&cs);
return 0;
}
return -1;
}
- cs_detach_endp(cs);
+ /* The app is still attached, the cs will not be released */
+ cs_detach_endp(&cs);
BUG_ON(cs->endp);
cs->endp = new_endp;
cs->endp->flags |= CS_EP_DETACHED;