From d540b36e8a1e9b366d38d1ce6f4ea97301d6d7c1 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Mon, 5 Nov 2018 18:37:53 +0100 Subject: [PATCH] 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. --- include/types/connection.h | 1 + src/mux_h2.c | 8 ++++++++ src/mux_pt.c | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/include/types/connection.h b/include/types/connection.h index ebc60e460..60036d6a1 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -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 */ }; diff --git a/src/mux_h2.c b/src/mux_h2.c index a643759f9..733cc1844 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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, diff --git a/src/mux_pt.c b/src/mux_pt.c index 25b1cfe0d..d7ddcde88 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -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,