MINOR: applet: add new wrappers to put chk/blk/str/chr to channel from appctx
The vast majority of calls to ci_putchk() etc are performed from applets which directly know an endpoint. Figuring the correct API (writing into input channel etc) isn't trivial for newcomers, and knowing that they must mark the flag indicating a buffer full condition isn't trivial either. Here we're adding wrappers to these functions but to be used directly from the appctx. That's already what is being done in multiple steps in the applet code, where the endp is derived from the appctx, then the cs from the endp, then the stream from the cs, then the channel from the stream, and so on. But this time the function doesn't require to know much of the internals, applet_putchr() writes a char from the appctx, and marks the buffer full if needed. Period. This will allow to remove a significant amount of obscure ci_putchk() and cs_ic() calls from the code, hence a significant number of possible mistakes.
This commit is contained in:
parent
2f2318df87
commit
15c25d5e1d
@ -26,7 +26,9 @@
|
|||||||
|
|
||||||
#include <haproxy/api.h>
|
#include <haproxy/api.h>
|
||||||
#include <haproxy/applet-t.h>
|
#include <haproxy/applet-t.h>
|
||||||
|
#include <haproxy/channel.h>
|
||||||
#include <haproxy/conn_stream.h>
|
#include <haproxy/conn_stream.h>
|
||||||
|
#include <haproxy/cs_utils.h>
|
||||||
#include <haproxy/list.h>
|
#include <haproxy/list.h>
|
||||||
#include <haproxy/pool.h>
|
#include <haproxy/pool.h>
|
||||||
#include <haproxy/session.h>
|
#include <haproxy/session.h>
|
||||||
@ -126,6 +128,71 @@ static inline struct stream *appctx_strm(const struct appctx *appctx)
|
|||||||
return __cs_strm(appctx->sedesc->sc);
|
return __cs_strm(appctx->sedesc->sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* writes chunk <chunk> into the input channel of the stream attached to this
|
||||||
|
* appctx's endpoint, and marks the RXBLK_ROOM on a channel full error. See
|
||||||
|
* ci_putchk() for the list of return codes.
|
||||||
|
*/
|
||||||
|
static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk)
|
||||||
|
{
|
||||||
|
struct sedesc *se = appctx->sedesc;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ci_putchk(cs_ic(se->sc), chunk);
|
||||||
|
if (ret == -1)
|
||||||
|
se_fl_set(se, SE_FL_RXBLK_ROOM);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* writes <len> chars from <blk> into the input channel of the stream attached
|
||||||
|
* to this appctx's endpoint, and marks the RXBLK_ROOM on a channel full error.
|
||||||
|
* See ci_putblk() for the list of return codes.
|
||||||
|
*/
|
||||||
|
static inline int applet_putblk(struct appctx *appctx, const char *blk, int len)
|
||||||
|
{
|
||||||
|
struct sedesc *se = appctx->sedesc;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ci_putblk(cs_ic(se->sc), blk, len);
|
||||||
|
if (ret == -1)
|
||||||
|
se_fl_set(se, SE_FL_RXBLK_ROOM);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* writes chars from <str> up to the trailing zero (excluded) into the input
|
||||||
|
* channel of the stream attached to this appctx's endpoint, and marks the
|
||||||
|
* RXBLK_ROOM on a channel full error. See ci_putstr() for the list of return
|
||||||
|
* codes.
|
||||||
|
*/
|
||||||
|
static inline int applet_putstr(struct appctx *appctx, const char *str)
|
||||||
|
{
|
||||||
|
struct sedesc *se = appctx->sedesc;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ci_putstr(cs_ic(se->sc), str);
|
||||||
|
if (ret == -1)
|
||||||
|
se_fl_set(se, SE_FL_RXBLK_ROOM);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* writes character <chr> into the input channel of the stream attached to this
|
||||||
|
* appctx's endpoint, and marks the RXBLK_ROOM on a channel full error. See
|
||||||
|
* ci_putchr() for the list of return codes.
|
||||||
|
*/
|
||||||
|
static inline int applet_putchr(struct appctx *appctx, char chr)
|
||||||
|
{
|
||||||
|
struct sedesc *se = appctx->sedesc;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ci_putchr(cs_ic(se->sc), chr);
|
||||||
|
if (ret == -1)
|
||||||
|
se_fl_set(se, SE_FL_RXBLK_ROOM);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _HAPROXY_APPLET_H */
|
#endif /* _HAPROXY_APPLET_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user