]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux: Add a new "avail_streams" method.
authorOlivier Houchard <ohouchard@haproxy.com>
Mon, 5 Nov 2018 17:37:53 +0000 (18:37 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 18 Nov 2018 20:44:06 +0000 (21:44 +0100)
Add a new method for mux, avail_streams, that returns the number of streams
still available for a mux.
For the mux_pt, it'll return 1 if the connection is in idle, or 0. For
the H2 mux, it'll return the max number of streams allowed, minus the number
of streams currently in use.

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

index ebc60e46054bbccec5bef0ec4dec670aadcb9acf..60036d6a118c58deb368c5f49ffe880942243574 100644 (file)
@@ -326,6 +326,7 @@ struct mux_ops {
        void (*show_fd)(struct buffer *, struct connection *); /* append some data about connection into chunk for "show fd" */
        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 */
        unsigned int flags;                           /* some flags characterizing the mux's capabilities (MX_FL_*) */
        char name[8];                                 /* mux layer name, zero-terminated */
 };
index a643759f915414c6577a06e4633559ba9231b6ac..733cc18445ea2e0d999b4b9495326cfe6895ca40 100644 (file)
@@ -339,6 +339,13 @@ static inline void h2_release_buf(struct h2c *h2c, struct buffer *bptr)
        }
 }
 
+static int h2_avail_streams(struct connection *conn)
+{
+       struct h2c *h2c = conn->mux_ctx;
+
+       return (h2_settings_max_concurrent_streams - h2c->nb_streams);
+}
+
 
 /*****************************************************************/
 /* functions below are dedicated to the mux setup and management */
@@ -3793,6 +3800,7 @@ const struct mux_ops h2_ops = {
        .attach = h2_attach,
        .get_first_cs = h2_get_first_cs,
        .detach = h2_detach,
+       .avail_streams = h2_avail_streams,
        .shutr = h2_shutr,
        .shutw = h2_shutw,
        .show_fd = h2_show_fd,
index 25b1cfe0df0f72d469fd0893424e4d6209447dea..d7ddcde88ca3188c47e282dd94a7ce477f84f289 100644 (file)
@@ -163,6 +163,13 @@ static void mux_pt_detach(struct conn_stream *cs)
        mux_pt_destroy(ctx);
 }
 
+static int mux_pt_avail_streams(struct connection *conn)
+{
+       struct mux_pt_ctx *ctx = conn->mux_ctx;
+
+       return (ctx->cs == NULL ? 1 : 0);
+}
+
 static void mux_pt_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
 {
        if (cs->flags & CS_FL_SHR)
@@ -261,6 +268,7 @@ const struct mux_ops mux_pt_ops = {
        .attach = mux_pt_attach,
        .get_first_cs = mux_pt_get_first_cs,
        .detach = mux_pt_detach,
+       .avail_streams = mux_pt_avail_streams,
        .shutr = mux_pt_shutr,
        .shutw = mux_pt_shutw,
        .flags = MX_FL_NONE,