MINOR: mux: Add a new "avail_streams" method.
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.
diff --git a/include/types/connection.h b/include/types/connection.h
index ebc60e4..60036d6 100644
--- a/include/types/connection.h
+++ b/include/types/connection.h
@@ -326,6 +326,7 @@
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 */
};
diff --git a/src/mux_h2.c b/src/mux_h2.c
index a643759..733cc18 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -339,6 +339,13 @@
}
}
+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 @@
.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,
diff --git a/src/mux_pt.c b/src/mux_pt.c
index 25b1cfe..d7ddcde 100644
--- a/src/mux_pt.c
+++ b/src/mux_pt.c
@@ -163,6 +163,13 @@
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 @@
.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,