#include <haproxy/xref-t.h>
/* flags for appctx->state */
-#define APPLET_WANT_DIE 0x01 /* applet was running and requested to die */
-#define APPLET_INBLK_ALLOC 0x02
-#define APPLET_INBLK_FULL 0x04
-#define APPLET_OUTBLK_ALLOC 0x08
-#define APPLET_OUTBLK_FULL 0x10
+#define APPLET_WANT_DIE 0x01 /* applet was running and requested to die */
/* Room for per-command context (mostly CLI commands but not only) */
#define APPLET_MAX_SVCCTX 88
+/* Appctx Flags */
+#define APPCTX_FL_INBLK_ALLOC 0x00000001
+#define APPCTX_FL_INBLK_FULL 0x00000002
+#define APPCTX_FL_OUTBLK_ALLOC 0x00000004
+#define APPCTX_FL_OUTBLK_FULL 0x00000008
+
struct appctx;
struct proxy;
struct stconn;
unsigned int st0; /* CLI state for stats, session state for peers */
unsigned int st1; /* prompt/payload (bitwise OR of APPCTX_CLI_ST1_*) for stats, session error for peers */
+ unsigned int flags; /* APPCTX_FL_* */
struct buffer inbuf;
struct buffer outbuf;
return __sc_strm(appctx->sedesc->sc);
}
+static forceinline void applet_fl_zero(struct appctx *appctx)
+{
+ appctx->flags = 0;
+}
+
+static forceinline void applet_fl_setall(struct appctx *appctx, uint all)
+{
+ appctx->flags = all;
+}
+
+static forceinline void applet_fl_set(struct appctx *appctx, uint on)
+{
+ appctx->flags |= on;
+}
+
+static forceinline void applet_fl_clr(struct appctx *appctx, uint off)
+{
+ appctx->flags &= ~off;
+}
+
+static forceinline uint applet_fl_test(const struct appctx *appctx, uint test)
+{
+ return !!(appctx->flags & test);
+}
+
+static forceinline uint applet_fl_get(const struct appctx *appctx)
+{
+ return appctx->flags;
+}
+
/* The applet announces it has more data to deliver to the stream's input
* buffer.
*/
appctx->t->process = task_run_applet;
appctx->t->context = appctx;
+ appctx->flags = 0;
appctx->inbuf = BUF_NULL;
appctx->outbuf = BUF_NULL;
struct appctx *appctx = arg;
struct stconn *sc = appctx_sc(appctx);
- if ((appctx->state & APPLET_INBLK_ALLOC) && b_alloc(&appctx->inbuf)) {
- appctx->state &= ~APPLET_INBLK_ALLOC;
+ if (applet_fl_test(appctx, APPCTX_FL_INBLK_ALLOC) && b_alloc(&appctx->inbuf)) {
+ applet_fl_clr(appctx, APPCTX_FL_INBLK_ALLOC);
TRACE_STATE("unblocking appctx, inbuf allocated", APPLET_EV_RECV|APPLET_EV_BLK|APPLET_EV_WAKE, appctx);
task_wakeup(appctx->t, TASK_WOKEN_RES);
return 1;
}
- if ((appctx->state & APPLET_OUTBLK_ALLOC) && b_alloc(&appctx->outbuf)) {
- appctx->state &= ~APPLET_OUTBLK_ALLOC;
+ if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC) && b_alloc(&appctx->outbuf)) {
+ applet_fl_clr(appctx, APPCTX_FL_OUTBLK_ALLOC);
TRACE_STATE("unblocking appctx, outbuf allocated", APPLET_EV_SEND|APPLET_EV_BLK|APPLET_EV_WAKE, appctx);
task_wakeup(appctx->t, TASK_WOKEN_RES);
return 1;
TRACE_ENTER(APPLET_EV_RECV, appctx);
- if (appctx->state & APPLET_OUTBLK_ALLOC)
+ if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC))
goto end;
if (!count)
goto end;
if (!appctx_get_buf(appctx, &appctx->outbuf)) {
- appctx->state |= APPLET_OUTBLK_ALLOC;
+ applet_fl_set(appctx, APPCTX_FL_OUTBLK_ALLOC);
TRACE_STATE("waiting for appctx outbuf allocation", APPLET_EV_RECV|APPLET_EV_BLK, appctx);
goto end;
}
done:
if (ret)
- appctx->state |= APPLET_OUTBLK_FULL;
+ applet_fl_clr(appctx, APPCTX_FL_OUTBLK_FULL);
if (b_data(&appctx->outbuf)) {
se_fl_set(appctx->sedesc, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
TRACE_ENTER(APPLET_EV_SEND, appctx);
- if (appctx->state & (APPLET_INBLK_FULL|APPLET_INBLK_ALLOC))
+ if (applet_fl_test(appctx, (APPCTX_FL_INBLK_FULL|APPCTX_FL_INBLK_ALLOC)))
goto end;
if (!count)
goto end;
if (!appctx_get_buf(appctx, &appctx->inbuf)) {
- appctx->state |= APPLET_INBLK_ALLOC;
+ applet_fl_set(appctx, APPCTX_FL_INBLK_ALLOC);
TRACE_STATE("waiting for appctx inbuf allocation", APPLET_EV_SEND|APPLET_EV_BLK, appctx);
goto end;
}
done:
if (ret < count) {
- appctx->state |= APPLET_INBLK_FULL;
+ applet_fl_set(appctx, APPCTX_FL_INBLK_FULL);
TRACE_STATE("report appctx inbuf is full", APPLET_EV_SEND|APPLET_EV_BLK, appctx);
}