diff --git a/include/haproxy/applet-t.h b/include/haproxy/applet-t.h index 51b3b4c8b..71fb57ecd 100644 --- a/include/haproxy/applet-t.h +++ b/include/haproxy/applet-t.h @@ -31,15 +31,17 @@ #include /* 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; @@ -69,6 +71,7 @@ struct appctx { 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; diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 9b4f5744b..6915eb3fc 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -145,6 +145,36 @@ static inline struct stream *appctx_strm(const struct appctx *appctx) 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. */ diff --git a/src/applet.c b/src/applet.c index d93e37a40..27c1f7f40 100644 --- a/src/applet.c +++ b/src/applet.c @@ -264,6 +264,7 @@ struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, int t appctx->t->process = task_run_applet; appctx->t->context = appctx; + appctx->flags = 0; appctx->inbuf = BUF_NULL; appctx->outbuf = BUF_NULL; @@ -414,15 +415,15 @@ int appctx_buf_available(void *arg) 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; @@ -455,14 +456,14 @@ size_t appctx_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig 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; } @@ -505,7 +506,7 @@ size_t appctx_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig 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); @@ -528,14 +529,14 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig 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; } @@ -567,7 +568,7 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig 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); }