MINOR: mux: Add a new method to get informations about a mux.
Add a new method, ctl(), to muxes. It uses a "enum mux_ctl_type" to
let it know which information we're asking for, and can output it either
directly by returning the expected value, or by using an optional argument.
"output" argument.
Right now, the only known mux_ctl_type is MUX_STATUS, that will return 0 if
the mux is not ready, or MUX_STATUS_READY if the mux is ready.
We probably want to backport this to 1.9 and 2.0.
(cherry picked from commit 9b8e11e691619b9cc0336f57bcdfacb015864a97)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/mux_h2.c b/src/mux_h2.c
index ac34a72..8116df4 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -3217,6 +3217,24 @@
return NULL;
}
+static int h2_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *output)
+{
+ int ret = 0;
+ struct h2c *h2c = conn->ctx;
+
+ switch (mux_ctl) {
+ case MUX_STATUS:
+ /* Only consider the mux to be ready if we're done with
+ * the preface and settings, and we had no error.
+ */
+ if (h2c->st0 >= H2_CS_FRAME_H && h2c->st0 < H2_CS_ERROR)
+ ret |= MUX_STATUS_READY;
+ return ret;
+ default:
+ return -1;
+ }
+}
+
/*
* Destroy the mux and the associated connection, if it is no longer used
*/
@@ -5932,6 +5950,7 @@
.used_streams = h2_used_streams,
.shutr = h2_shutr,
.shutw = h2_shutw,
+ .ctl = h2_ctl,
.show_fd = h2_show_fd,
.flags = MX_FL_CLEAN_ABRT,
.name = "H2",
@@ -5960,6 +5979,7 @@
.used_streams = h2_used_streams,
.shutr = h2_shutr,
.shutw = h2_shutw,
+ .ctl = h2_ctl,
.show_fd = h2_show_fd,
.flags = MX_FL_CLEAN_ABRT|MX_FL_HTX,
.name = "H2",