diff --git a/include/types/connection.h b/include/types/connection.h index 60036d6a1..2ed39f69c 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -327,6 +327,7 @@ struct mux_ops { int (*subscribe)(struct conn_stream *cs, int event_type, void *param); /* Subscribe to events, such as "being able to send" */ int (*unsubscribe)(struct conn_stream *cs, int event_type, void *param); /* Unsubscribe to events */ int (*avail_streams)(struct connection *conn); /* Returns the number of streams still available for a connection */ + void (*destroy)(struct connection *conn); /* Let the mux know one of its users left, so it may have to disappear */ unsigned int flags; /* some flags characterizing the mux's capabilities (MX_FL_*) */ char name[8]; /* mux layer name, zero-terminated */ }; diff --git a/src/mux_h2.c b/src/mux_h2.c index 733cc1844..87b5cb1dc 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -2478,7 +2478,6 @@ static int h2_wake(struct connection *conn) return (h2_process(h2c)); } - /* Connection timeout management. The principle is that if there's no receipt * nor sending for a certain amount of time, the connection is closed. If the * MUX buffer still has lying data or is not allocatable, the connection is @@ -2567,6 +2566,17 @@ static const struct conn_stream *h2_get_first_cs(const struct connection *conn) return NULL; } +/* + * Destroy the mux and the associated connection, if it is no longer used + */ +static void h2_destroy(struct connection *conn) +{ + struct h2c *h2c = conn->mux_ctx; + + if (eb_is_empty(&h2c->streams_by_id)) + h2_release(h2c->conn); +} + /* * Detach the stream from the connection and possibly release the connection. */ @@ -3800,6 +3810,7 @@ const struct mux_ops h2_ops = { .attach = h2_attach, .get_first_cs = h2_get_first_cs, .detach = h2_detach, + .destroy = h2_destroy, .avail_streams = h2_avail_streams, .shutr = h2_shutr, .shutw = h2_shutw, diff --git a/src/mux_pt.c b/src/mux_pt.c index d7ddcde88..a0f039775 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -149,6 +149,12 @@ static const struct conn_stream *mux_pt_get_first_cs(const struct connection *co return cs; } +/* Destroy the mux and the associated connection */ +static void mux_pt_destroy_meth(struct connection *conn) +{ + mux_pt_destroy(conn->mux_ctx); +} + /* * Detach the stream from the connection and possibly release the connection. */ @@ -269,6 +275,7 @@ const struct mux_ops mux_pt_ops = { .get_first_cs = mux_pt_get_first_cs, .detach = mux_pt_detach, .avail_streams = mux_pt_avail_streams, + .destroy = mux_pt_destroy_meth, .shutr = mux_pt_shutr, .shutw = mux_pt_shutw, .flags = MX_FL_NONE,