[MINOR] stream_interface: make use of an applet descriptor for IO handlers
I/O handlers are still delicate to manipulate. They have no type, they're
just raw functions which have no knowledge of themselves. Let's have them
declared as applets once for all. That way we can have multiple applets
share the same handler functions and we can store their names there. When
we later need to add more parameters (eg: usage stats), we'll be able to
do so in the applets themselves.
The CLI functions has been prefixed with "cli" instead of "stats" as it's
clearly what is going on there.
The applet descriptor in the stream interface should get all the applet
specific data (st0, ...) but this will be done in the next patch so that
we don't pollute this one too much.
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 081e4cd..2630eed 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -84,7 +84,7 @@
int stats_accept(struct session *s)
{
/* we have a dedicated I/O handler for the stats */
- stream_int_register_handler(&s->si[1], stats_io_handler);
+ stream_int_register_handler(&s->si[1], &cli_applet);
s->si[1].private = s;
s->si[1].st1 = 0;
s->si[1].st0 = STAT_CLI_INIT;
@@ -848,7 +848,7 @@
* STAT_CLI_* constants. si->st1 is used to indicate whether prompt is enabled
* or not.
*/
-void stats_io_handler(struct stream_interface *si)
+static void cli_io_handler(struct stream_interface *si)
{
struct session *s = si->private;
struct buffer *req = si->ob;
@@ -1200,7 +1200,7 @@
* si->st0 becomes non-zero once the transfer is finished. The handler
* automatically unregisters itself once transfer is complete.
*/
-void http_stats_io_handler(struct stream_interface *si)
+static void http_stats_io_handler(struct stream_interface *si)
{
struct session *s = si->private;
struct buffer *req = si->ob;
@@ -3583,6 +3583,15 @@
return 1;
}
+struct si_applet http_stats_applet = {
+ .name = "<STATS>", /* used for logging */
+ .fct = http_stats_io_handler,
+};
+
+struct si_applet cli_applet = {
+ .name = "<CLI>", /* used for logging */
+ .fct = cli_io_handler,
+};
static struct cfg_kw_list cfg_kws = {{ },{
{ CFG_GLOBAL, "stats", stats_parse_global },