MAJOR: conn-stream: Share endpoint struct between the CS and the mux/applet
The conn-stream endpoint is now shared between the conn-stream and the
applet or the multiplexer. If the mux or the applet is created first, it is
responsible to also create the endpoint and share it with the conn-stream.
If the conn-stream is created first, it is the opposite.
When the endpoint is only owned by an applet or a mux, it is called an
orphan endpoint (there is no conn-stream). When it is only owned by a
conn-stream, it is called a detached endpoint (there is no mux/applet).
The last entity that owns an endpoint is responsible to release it. When a
mux or an applet is detached from a conn-stream, the conn-stream
relinquishes the endpoint to recreate a new one. This way, the endpoint
state is never lost for the mux or the applet.
diff --git a/src/cli.c b/src/cli.c
index 25d28f1..665631f 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -2753,8 +2753,14 @@
* connection.
*/
if (!si_conn_ready(cs_si(s->csb))) {
- cs_detach_endp(s->csb);
s->srv_conn = NULL;
+ if (cs_reset_endp(s->csb) < 0) {
+ if (!cs_si(s->csb)->err_type)
+ cs_si(s->csb)->err_type = SI_ET_CONN_OTHER;
+ if (s->srv_error)
+ s->srv_error(s, cs_si(s->csb));
+ return 1;
+ }
}
sockaddr_free(&(cs_si(s->csb)->dst));