]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux: Add a destroy() method.
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 6 Nov 2018 15:32:42 +0000 (16:32 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 18 Nov 2018 20:44:53 +0000 (21:44 +0100)
Add a new method to muxes, destroy(), that is responsible for destroying
the mux and the associated connection, to be used for server connections.

include/types/connection.h
src/mux_h2.c
src/mux_pt.c

index 60036d6a118c58deb368c5f49ffe880942243574..2ed39f69c770861d5f7b4c287ec87beb923cf00f 100644 (file)
@@ -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 */
 };
index 733cc18445ea2e0d999b4b9495326cfe6895ca40..87b5cb1dcf3c5f2f169eb23917f6cec7d984eca2 100644 (file)
@@ -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,
index d7ddcde88ca3188c47e282dd94a7ce477f84f289..a0f039775824c36e7507bec85c6a865c9cf1c199 100644 (file)
@@ -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,