mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MINOR: applet: Add flags on the appctx and stop abusing its state
Till now, we've extended the appctx state to add some flags. However, the field name is misleading. So a bitfield was added to handle real flags. And helper functions to manipulate this bitfield were added.
This commit is contained in:
parent
c0527261cf
commit
e8655546b7
@ -31,15 +31,17 @@
|
|||||||
#include <haproxy/xref-t.h>
|
#include <haproxy/xref-t.h>
|
||||||
|
|
||||||
/* flags for appctx->state */
|
/* flags for appctx->state */
|
||||||
#define APPLET_WANT_DIE 0x01 /* applet was running and requested to die */
|
#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
|
|
||||||
|
|
||||||
/* Room for per-command context (mostly CLI commands but not only) */
|
/* Room for per-command context (mostly CLI commands but not only) */
|
||||||
#define APPLET_MAX_SVCCTX 88
|
#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 appctx;
|
||||||
struct proxy;
|
struct proxy;
|
||||||
struct stconn;
|
struct stconn;
|
||||||
@ -69,6 +71,7 @@ struct appctx {
|
|||||||
unsigned int st0; /* CLI state for stats, session state for peers */
|
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 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 inbuf;
|
||||||
struct buffer outbuf;
|
struct buffer outbuf;
|
||||||
|
|
||||||
|
@ -145,6 +145,36 @@ static inline struct stream *appctx_strm(const struct appctx *appctx)
|
|||||||
return __sc_strm(appctx->sedesc->sc);
|
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
|
/* The applet announces it has more data to deliver to the stream's input
|
||||||
* buffer.
|
* buffer.
|
||||||
*/
|
*/
|
||||||
|
21
src/applet.c
21
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->process = task_run_applet;
|
||||||
appctx->t->context = appctx;
|
appctx->t->context = appctx;
|
||||||
|
|
||||||
|
appctx->flags = 0;
|
||||||
appctx->inbuf = BUF_NULL;
|
appctx->inbuf = BUF_NULL;
|
||||||
appctx->outbuf = BUF_NULL;
|
appctx->outbuf = BUF_NULL;
|
||||||
|
|
||||||
@ -414,15 +415,15 @@ int appctx_buf_available(void *arg)
|
|||||||
struct appctx *appctx = arg;
|
struct appctx *appctx = arg;
|
||||||
struct stconn *sc = appctx_sc(appctx);
|
struct stconn *sc = appctx_sc(appctx);
|
||||||
|
|
||||||
if ((appctx->state & APPLET_INBLK_ALLOC) && b_alloc(&appctx->inbuf)) {
|
if (applet_fl_test(appctx, APPCTX_FL_INBLK_ALLOC) && b_alloc(&appctx->inbuf)) {
|
||||||
appctx->state &= ~APPLET_INBLK_ALLOC;
|
applet_fl_clr(appctx, APPCTX_FL_INBLK_ALLOC);
|
||||||
TRACE_STATE("unblocking appctx, inbuf allocated", APPLET_EV_RECV|APPLET_EV_BLK|APPLET_EV_WAKE, appctx);
|
TRACE_STATE("unblocking appctx, inbuf allocated", APPLET_EV_RECV|APPLET_EV_BLK|APPLET_EV_WAKE, appctx);
|
||||||
task_wakeup(appctx->t, TASK_WOKEN_RES);
|
task_wakeup(appctx->t, TASK_WOKEN_RES);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((appctx->state & APPLET_OUTBLK_ALLOC) && b_alloc(&appctx->outbuf)) {
|
if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC) && b_alloc(&appctx->outbuf)) {
|
||||||
appctx->state &= ~APPLET_OUTBLK_ALLOC;
|
applet_fl_clr(appctx, APPCTX_FL_OUTBLK_ALLOC);
|
||||||
TRACE_STATE("unblocking appctx, outbuf allocated", APPLET_EV_SEND|APPLET_EV_BLK|APPLET_EV_WAKE, appctx);
|
TRACE_STATE("unblocking appctx, outbuf allocated", APPLET_EV_SEND|APPLET_EV_BLK|APPLET_EV_WAKE, appctx);
|
||||||
task_wakeup(appctx->t, TASK_WOKEN_RES);
|
task_wakeup(appctx->t, TASK_WOKEN_RES);
|
||||||
return 1;
|
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);
|
TRACE_ENTER(APPLET_EV_RECV, appctx);
|
||||||
|
|
||||||
if (appctx->state & APPLET_OUTBLK_ALLOC)
|
if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if (!count)
|
if (!count)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if (!appctx_get_buf(appctx, &appctx->outbuf)) {
|
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);
|
TRACE_STATE("waiting for appctx outbuf allocation", APPLET_EV_RECV|APPLET_EV_BLK, appctx);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -505,7 +506,7 @@ size_t appctx_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
if (ret)
|
if (ret)
|
||||||
appctx->state |= APPLET_OUTBLK_FULL;
|
applet_fl_clr(appctx, APPCTX_FL_OUTBLK_FULL);
|
||||||
|
|
||||||
if (b_data(&appctx->outbuf)) {
|
if (b_data(&appctx->outbuf)) {
|
||||||
se_fl_set(appctx->sedesc, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
|
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);
|
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;
|
goto end;
|
||||||
|
|
||||||
if (!count)
|
if (!count)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if (!appctx_get_buf(appctx, &appctx->inbuf)) {
|
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);
|
TRACE_STATE("waiting for appctx inbuf allocation", APPLET_EV_SEND|APPLET_EV_BLK, appctx);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -567,7 +568,7 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
if (ret < count) {
|
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);
|
TRACE_STATE("report appctx inbuf is full", APPLET_EV_SEND|APPLET_EV_BLK, appctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user