MINOR: stats: Use the applet API to write data
stats_putchk() is updated to use the applet API instead of the channel API
to write data. To do so, the appctx is passed as parameter instead of the
channel. This way, the applet does not need to take care to request more
room it it fails to put data into the channel's buffer.
diff --git a/include/haproxy/stats.h b/include/haproxy/stats.h
index 90a4f51..f9e6d97 100644
--- a/include/haproxy/stats.h
+++ b/include/haproxy/stats.h
@@ -45,7 +45,7 @@
extern THREAD_LOCAL struct field *stat_l[];
struct htx;
-int stats_putchk(struct channel *chn, struct htx *htx);
+int stats_putchk(struct appctx *appctx, struct htx *htx);
int stats_dump_one_line(const struct field *stats, size_t stats_count, struct appctx *appctx);
diff --git a/src/resolvers.c b/src/resolvers.c
index 1213303..4a9209e 100644
--- a/src/resolvers.c
+++ b/src/resolvers.c
@@ -2671,7 +2671,6 @@
struct list *stat_modules)
{
struct appctx *appctx = __sc_appctx(sc);
- struct channel *rep = sc_ic(sc);
struct stats_module *mod;
size_t idx = 0;
@@ -2687,13 +2686,12 @@
if (!stats_dump_one_line(stats, idx, appctx))
return 0;
- if (!stats_putchk(rep, NULL))
+ if (!stats_putchk(appctx, NULL))
goto full;
return 1;
full:
- sc_need_room(sc);
return 0;
}
@@ -2740,7 +2738,6 @@
return 1;
full:
- sc_need_room(sc);
return 0;
}
diff --git a/src/stats.c b/src/stats.c
index 823c8f6..56f62d8 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -305,20 +305,26 @@
static void stats_dump_json_schema(struct buffer *out);
-int stats_putchk(struct channel *chn, struct htx *htx)
+int stats_putchk(struct appctx *appctx, struct htx *htx)
{
+ struct stconn *sc = appctx_sc(appctx);
+ struct channel *chn = sc_ic(sc);
struct buffer *chk = &trash_chunk;
if (htx) {
- if (chk->data >= channel_htx_recv_max(chn, htx))
+ if (chk->data >= channel_htx_recv_max(chn, htx)) {
+ sc_need_room(sc, chk->data);
return 0;
- if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data)))
+ }
+ if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data))) {
+ sc_need_room(sc, 0);
return 0;
+ }
channel_add_input(chn, chk->data);
chk->data = 0;
}
else {
- if (ci_putchk(chn, chk) == -1)
+ if (applet_putchk(appctx, chk) == -1)
return 0;
}
return 1;
@@ -3196,7 +3202,7 @@
case STAT_PX_ST_TH:
if (ctx->flags & STAT_FMT_HTML) {
stats_dump_html_px_hdr(sc, px);
- if (!stats_putchk(rep, htx))
+ if (!stats_putchk(appctx, htx))
goto full;
}
@@ -3206,7 +3212,7 @@
case STAT_PX_ST_FE:
/* print the frontend */
if (stats_dump_fe_stats(sc, px)) {
- if (!stats_putchk(rep, htx))
+ if (!stats_putchk(appctx, htx))
goto full;
ctx->flags |= STAT_STARTED;
if (ctx->field)
@@ -3244,7 +3250,7 @@
/* print the frontend */
if (stats_dump_li_stats(sc, px, l)) {
- if (!stats_putchk(rep, htx))
+ if (!stats_putchk(appctx, htx))
goto full;
ctx->flags |= STAT_STARTED;
if (ctx->field)
@@ -3327,7 +3333,7 @@
}
if (stats_dump_sv_stats(sc, px, sv)) {
- if (!stats_putchk(rep, htx))
+ if (!stats_putchk(appctx, htx))
goto full;
ctx->flags |= STAT_STARTED;
if (ctx->field)
@@ -3342,7 +3348,7 @@
case STAT_PX_ST_BE:
/* print the backend */
if (stats_dump_be_stats(sc, px)) {
- if (!stats_putchk(rep, htx))
+ if (!stats_putchk(appctx, htx))
goto full;
ctx->flags |= STAT_STARTED;
if (ctx->field)
@@ -3356,7 +3362,7 @@
case STAT_PX_ST_END:
if (ctx->flags & STAT_FMT_HTML) {
stats_dump_html_px_end(sc, px);
- if (!stats_putchk(rep, htx))
+ if (!stats_putchk(appctx, htx))
goto full;
}
@@ -3372,7 +3378,6 @@
}
full:
- sc_need_room(sc);
/* restore previous field */
ctx->field = current_field;
return 0;
@@ -3891,7 +3896,6 @@
{
struct appctx *appctx = __sc_appctx(sc);
struct show_stat_ctx *ctx = appctx->svcctx;
- struct channel *rep = sc_ic(sc);
enum stats_domain domain = ctx->domain;
chunk_reset(&trash_chunk);
@@ -3911,7 +3915,7 @@
else if (!(ctx->flags & STAT_FMT_TYPED))
stats_dump_csv_header(ctx->domain);
- if (!stats_putchk(rep, htx))
+ if (!stats_putchk(appctx, htx))
goto full;
if (ctx->flags & STAT_JSON_SCHM) {
@@ -3924,7 +3928,7 @@
case STAT_STATE_INFO:
if (ctx->flags & STAT_FMT_HTML) {
stats_dump_html_info(sc, uri);
- if (!stats_putchk(rep, htx))
+ if (!stats_putchk(appctx, htx))
goto full;
}
@@ -3963,7 +3967,7 @@
stats_dump_html_end();
else
stats_dump_json_end();
- if (!stats_putchk(rep, htx))
+ if (!stats_putchk(appctx, htx))
goto full;
}
@@ -3980,7 +3984,6 @@
}
full:
- sc_need_room(sc);
return 0;
}