mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 13:21:29 +02:00
MINOR: applet: Rely on applet flag to detect the new api
Instead of setting a flag on the applet context by checking the defined callback functions of the applet to know if an applet is using the new API or not, we can now rely on the applet flags itself. By checking APPLET_FL_NEW_API flag, it does the job. APPCTX_FL_INOUT_BUFS flag is thus removed.
This commit is contained in:
parent
3da1d63749
commit
3de6c375aa
@ -47,7 +47,7 @@
|
||||
#define APPCTX_FL_ERROR 0x00000080
|
||||
#define APPCTX_FL_SHUTDOWN 0x00000100 /* applet was shut down (->release() called if any). No more data exchange with SCs */
|
||||
#define APPCTX_FL_WANT_DIE 0x00000200 /* applet was running and requested to die */
|
||||
#define APPCTX_FL_INOUT_BUFS 0x00000400 /* applet uses its own buffers */
|
||||
/* unused: 0x00000400 */
|
||||
#define APPCTX_FL_FASTFWD 0x00000800 /* zero-copy forwarding is in-use, don't fill the outbuf */
|
||||
#define APPCTX_FL_IN_MAYALLOC 0x00001000 /* applet may try again to allocate its inbuf */
|
||||
#define APPCTX_FL_OUT_MAYALLOC 0x00002000 /* applet may try again to allocate its outbuf */
|
||||
@ -73,8 +73,8 @@ static forceinline char *appctx_show_flags(char *buf, size_t len, const char *de
|
||||
_(APPCTX_FL_OUTBLK_ALLOC, _(APPCTX_FL_OUTBLK_FULL,
|
||||
_(APPCTX_FL_EOI, _(APPCTX_FL_EOS,
|
||||
_(APPCTX_FL_ERR_PENDING, _(APPCTX_FL_ERROR,
|
||||
_(APPCTX_FL_SHUTDOWN, _(APPCTX_FL_WANT_DIE, _(APPCTX_FL_INOUT_BUFS,
|
||||
_(APPCTX_FL_FASTFWD, _(APPCTX_FL_IN_MAYALLOC, _(APPCTX_FL_OUT_MAYALLOC))))))))))))));
|
||||
_(APPCTX_FL_SHUTDOWN, _(APPCTX_FL_WANT_DIE,
|
||||
_(APPCTX_FL_FASTFWD, _(APPCTX_FL_IN_MAYALLOC, _(APPCTX_FL_OUT_MAYALLOC)))))))))))));
|
||||
/* epilogue */
|
||||
_(~0U);
|
||||
return buf;
|
||||
|
@ -288,7 +288,7 @@ static inline void applet_expect_data(struct appctx *appctx)
|
||||
*/
|
||||
static inline struct buffer *applet_get_inbuf(struct appctx *appctx)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
if (applet_fl_test(appctx, APPCTX_FL_INBLK_ALLOC) || !appctx_get_buf(appctx, &appctx->inbuf))
|
||||
return NULL;
|
||||
return &appctx->inbuf;
|
||||
@ -303,7 +303,7 @@ static inline struct buffer *applet_get_inbuf(struct appctx *appctx)
|
||||
*/
|
||||
static inline struct buffer *applet_get_outbuf(struct appctx *appctx)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC|APPCTX_FL_OUTBLK_FULL) ||
|
||||
!appctx_get_buf(appctx, &appctx->outbuf))
|
||||
return NULL;
|
||||
@ -316,7 +316,7 @@ static inline struct buffer *applet_get_outbuf(struct appctx *appctx)
|
||||
/* Returns the amount of data in the input buffer (see applet_get_inbuf) */
|
||||
static inline size_t applet_input_data(const struct appctx *appctx)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS)
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API)
|
||||
return b_data(&appctx->inbuf);
|
||||
else
|
||||
return co_data(sc_oc(appctx_sc(appctx)));
|
||||
@ -325,7 +325,7 @@ static inline size_t applet_input_data(const struct appctx *appctx)
|
||||
/* Returns the amount of HTX data in the input buffer (see applet_get_inbuf) */
|
||||
static inline size_t applet_htx_input_data(const struct appctx *appctx)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS)
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API)
|
||||
return htx_used_space(htxbuf(&appctx->inbuf));
|
||||
else
|
||||
return co_data(sc_oc(appctx_sc(appctx)));
|
||||
@ -340,7 +340,7 @@ static inline size_t applet_htx_input_data(const struct appctx *appctx)
|
||||
*/
|
||||
static inline void applet_skip_input(struct appctx *appctx, size_t len)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
b_del(&appctx->inbuf, len);
|
||||
applet_fl_clr(appctx, APPCTX_FL_INBLK_FULL);
|
||||
}
|
||||
@ -352,7 +352,7 @@ static inline void applet_skip_input(struct appctx *appctx, size_t len)
|
||||
*/
|
||||
static inline void applet_reset_input(struct appctx *appctx)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
b_reset(&appctx->inbuf);
|
||||
applet_fl_clr(appctx, APPCTX_FL_INBLK_FULL);
|
||||
}
|
||||
@ -364,7 +364,7 @@ static inline void applet_reset_input(struct appctx *appctx)
|
||||
*/
|
||||
static inline size_t applet_output_room(const struct appctx *appctx)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS)
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API)
|
||||
return b_room(&appctx->outbuf);
|
||||
else
|
||||
return channel_recv_max(sc_ic(appctx_sc(appctx)));
|
||||
@ -374,7 +374,7 @@ static inline size_t applet_output_room(const struct appctx *appctx)
|
||||
*/
|
||||
static inline size_t applet_htx_output_room(const struct appctx *appctx)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS)
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API)
|
||||
return htx_free_data_space(htxbuf(&appctx->outbuf));
|
||||
else
|
||||
return channel_recv_max(sc_ic(appctx_sc(appctx)));
|
||||
@ -390,7 +390,7 @@ static inline size_t applet_htx_output_room(const struct appctx *appctx)
|
||||
*/
|
||||
static inline void applet_need_room(struct appctx *appctx, size_t room_needed)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS)
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API)
|
||||
applet_have_more_data(appctx);
|
||||
else
|
||||
sc_need_room(appctx_sc(appctx), room_needed);
|
||||
@ -402,7 +402,7 @@ static inline int _applet_putchk(struct appctx *appctx, struct buffer *chunk,
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
if (unlikely(stress) ?
|
||||
b_data(&appctx->outbuf) :
|
||||
b_data(chunk) > b_room(&appctx->outbuf)) {
|
||||
@ -457,7 +457,7 @@ static inline int applet_putblk(struct appctx *appctx, const char *blk, int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
if (len > b_room(&appctx->outbuf)) {
|
||||
applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
|
||||
ret = -1;
|
||||
@ -493,7 +493,7 @@ static inline int applet_putstr(struct appctx *appctx, const char *str)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
int len = strlen(str);
|
||||
|
||||
if (len > b_room(&appctx->outbuf)) {
|
||||
@ -529,7 +529,7 @@ static inline int applet_putchr(struct appctx *appctx, char chr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
if (b_full(&appctx->outbuf)) {
|
||||
applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
|
||||
ret = -1;
|
||||
@ -558,7 +558,7 @@ static inline int applet_putchr(struct appctx *appctx, char chr)
|
||||
|
||||
static inline int applet_may_get(const struct appctx *appctx, size_t len)
|
||||
{
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
if (len > b_data(&appctx->inbuf)) {
|
||||
if (se_fl_test(appctx->sedesc, SE_FL_SHW))
|
||||
return -1;
|
||||
@ -593,7 +593,7 @@ static inline int applet_getchar(const struct appctx *appctx, char *c)
|
||||
ret = applet_may_get(appctx, 1);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
*c = ((appctx->flags & APPCTX_FL_INOUT_BUFS)
|
||||
*c = ((appctx->applet->flags & APPLET_FL_NEW_API)
|
||||
? *(b_head(&appctx->inbuf))
|
||||
: *(co_head(sc_oc(appctx_sc(appctx)))));
|
||||
|
||||
@ -622,7 +622,7 @@ static inline int applet_getblk(const struct appctx *appctx, char *blk, int len,
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
|
||||
buf = ((appctx->flags & APPCTX_FL_INOUT_BUFS)
|
||||
buf = ((appctx->applet->flags & APPLET_FL_NEW_API)
|
||||
? &appctx->inbuf
|
||||
: sc_ob(appctx_sc(appctx)));
|
||||
return b_getblk(buf, blk, len, offset);
|
||||
@ -654,7 +654,7 @@ static inline int applet_getword(const struct appctx *appctx, char *str, int len
|
||||
if (ret <= 0)
|
||||
goto out;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
buf = &appctx->inbuf;
|
||||
input = b_data(buf);
|
||||
}
|
||||
@ -681,7 +681,7 @@ static inline int applet_getword(const struct appctx *appctx, char *str, int len
|
||||
p = b_next(buf, p);
|
||||
}
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
if (ret < len && (ret < input || b_room(buf)) &&
|
||||
!se_fl_test(appctx->sedesc, SE_FL_SHW))
|
||||
ret = 0;
|
||||
@ -741,7 +741,7 @@ static inline int applet_getblk_nc(const struct appctx *appctx, const char **blk
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
buf = &appctx->inbuf;
|
||||
max = b_data(buf);
|
||||
}
|
||||
@ -797,7 +797,7 @@ static inline int applet_getword_nc(const struct appctx *appctx, const char **bl
|
||||
* the resulting string is made of the concatenation of the pending
|
||||
* blocks (1 or 2).
|
||||
*/
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (appctx->applet->flags & APPLET_FL_NEW_API) {
|
||||
if (b_full(&appctx->inbuf) || se_fl_test(appctx->sedesc, SE_FL_SHW))
|
||||
return ret;
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ static inline int sc_is_send_allowed(const struct stconn *sc)
|
||||
if (sc->flags & SC_FL_SHUT_DONE)
|
||||
return 0;
|
||||
|
||||
if (!sc_appctx(sc) || !(__sc_appctx(sc)->flags & APPCTX_FL_INOUT_BUFS))
|
||||
if (!sc_appctx(sc) || !(__sc_appctx(sc)->applet->flags & APPLET_FL_NEW_API))
|
||||
return !sc_ep_test(sc, SE_FL_WAIT_DATA | SE_FL_WONT_CONSUME);
|
||||
|
||||
if (sc_ep_test(sc, SE_FL_WONT_CONSUME))
|
||||
|
@ -274,12 +274,9 @@ struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, int t
|
||||
appctx->outbuf = BUF_NULL;
|
||||
appctx->to_forward = 0;
|
||||
|
||||
if (applet->rcv_buf != NULL && applet->snd_buf != NULL) {
|
||||
appctx->t->process = task_process_applet;
|
||||
applet_fl_set(appctx, APPCTX_FL_INOUT_BUFS);
|
||||
}
|
||||
else
|
||||
appctx->t->process = task_run_applet;
|
||||
appctx->t->process = ((applet->flags & APPLET_FL_NEW_API)
|
||||
? task_process_applet
|
||||
: task_run_applet);
|
||||
appctx->t->context = appctx;
|
||||
|
||||
LIST_INIT(&appctx->buffer_wait.list);
|
||||
|
@ -2194,7 +2194,7 @@ int sc_applet_recv(struct stconn *sc)
|
||||
*/
|
||||
int sc_applet_sync_recv(struct stconn *sc)
|
||||
{
|
||||
if (!(__sc_appctx(sc)->flags & APPCTX_FL_INOUT_BUFS))
|
||||
if (!(__sc_appctx(sc)->applet->flags & APPLET_FL_NEW_API))
|
||||
return 0;
|
||||
|
||||
if (!sc_state_in(sc->state, SC_SB_RDY|SC_SB_EST))
|
||||
@ -2295,7 +2295,7 @@ void sc_applet_sync_send(struct stconn *sc)
|
||||
|
||||
oc->flags &= ~CF_WRITE_EVENT;
|
||||
|
||||
if (!(__sc_appctx(sc)->flags & APPCTX_FL_INOUT_BUFS))
|
||||
if (!(__sc_appctx(sc)->applet->flags & APPLET_FL_NEW_API))
|
||||
return;
|
||||
|
||||
if (sc->flags & SC_FL_SHUT_DONE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user