mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MEDIUM: applet: Handle applets with their own buffers in put functions
applet_putchk() and other similar functions are now testing the applet's type to use the applet's outbuf instead of the channel's buffer. This will ease applets convertion because most of them relies on these functions.
This commit is contained in:
parent
1380b97285
commit
2c6321842b
@ -276,9 +276,21 @@ static inline void applet_expect_data(struct appctx *appctx)
|
||||
*/
|
||||
static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk)
|
||||
{
|
||||
struct sedesc *se = appctx->sedesc;
|
||||
int ret;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (b_data(chunk) > b_room(&appctx->outbuf)) {
|
||||
applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
|
||||
ret = -1;
|
||||
}
|
||||
else {
|
||||
ret = b_putblk(&appctx->outbuf, b_head(chunk), b_data(chunk));
|
||||
chunk->data -= ret;
|
||||
}
|
||||
}
|
||||
else {
|
||||
struct sedesc *se = appctx->sedesc;
|
||||
|
||||
ret = ci_putchk(sc_ic(se->sc), chunk);
|
||||
if (ret < 0) {
|
||||
/* XXX: Handle all errors as a lack of space because callers
|
||||
@ -289,7 +301,7 @@ static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk)
|
||||
sc_need_room(se->sc, chunk->data);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -299,9 +311,19 @@ static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk)
|
||||
*/
|
||||
static inline int applet_putblk(struct appctx *appctx, const char *blk, int len)
|
||||
{
|
||||
struct sedesc *se = appctx->sedesc;
|
||||
int ret;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (len > b_room(&appctx->outbuf)) {
|
||||
applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
ret = b_putblk(&appctx->outbuf, blk, len);
|
||||
}
|
||||
else {
|
||||
struct sedesc *se = appctx->sedesc;
|
||||
|
||||
ret = ci_putblk(sc_ic(se->sc), blk, len);
|
||||
if (ret < -1) {
|
||||
/* XXX: Handle all errors as a lack of space because callers
|
||||
@ -312,6 +334,7 @@ static inline int applet_putblk(struct appctx *appctx, const char *blk, int len)
|
||||
sc_need_room(se->sc, len);
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -323,9 +346,21 @@ static inline int applet_putblk(struct appctx *appctx, const char *blk, int len)
|
||||
*/
|
||||
static inline int applet_putstr(struct appctx *appctx, const char *str)
|
||||
{
|
||||
struct sedesc *se = appctx->sedesc;
|
||||
int ret;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
int len = strlen(str);
|
||||
|
||||
if (len > b_room(&appctx->outbuf)) {
|
||||
applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
ret = b_putblk(&appctx->outbuf, str, len);
|
||||
}
|
||||
else {
|
||||
struct sedesc *se = appctx->sedesc;
|
||||
|
||||
ret = ci_putstr(sc_ic(se->sc), str);
|
||||
if (ret == -1) {
|
||||
/* XXX: Handle all errors as a lack of space because callers
|
||||
@ -336,7 +371,7 @@ static inline int applet_putstr(struct appctx *appctx, const char *str)
|
||||
sc_need_room(se->sc, strlen(str));
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -346,9 +381,21 @@ static inline int applet_putstr(struct appctx *appctx, const char *str)
|
||||
*/
|
||||
static inline int applet_putchr(struct appctx *appctx, char chr)
|
||||
{
|
||||
struct sedesc *se = appctx->sedesc;
|
||||
int ret;
|
||||
|
||||
if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
|
||||
if (b_full(&appctx->outbuf)) {
|
||||
applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
|
||||
ret = -1;
|
||||
}
|
||||
else {
|
||||
b_putchr(&appctx->outbuf, chr);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
struct sedesc *se = appctx->sedesc;
|
||||
|
||||
ret = ci_putchr(sc_ic(se->sc), chr);
|
||||
if (ret == -1) {
|
||||
/* XXX: Handle all errors as a lack of space because callers
|
||||
@ -359,7 +406,7 @@ static inline int applet_putchr(struct appctx *appctx, char chr)
|
||||
sc_need_room(se->sc, 1);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user