]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Let's applets .snd_buf function deal with full input buffers
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 20 Feb 2024 07:29:50 +0000 (08:29 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 28 Mar 2024 16:32:55 +0000 (17:32 +0100)
It is now the responsbility of applets .snd_buf callback function to notify
the input buffer is full. This will allow the applets to not consume all
data waiting for more data. Of course, it is only useful for applets using a
custom .snd_buf callback function.

src/applet.c

index 90aa89f5daac1910faa40f0730c4880b7d78a46e..8e7ac445b72927fdf9193bfba83d8fab7409cc04 100644 (file)
@@ -593,14 +593,25 @@ size_t appctx_htx_snd_buf(struct appctx *appctx, struct buffer *buf, size_t coun
        htx_to_buf(appctx_htx, &appctx->outbuf);
        htx_to_buf(buf_htx, buf);
        ret -= buf_htx->data;
-
 end:
+       if (ret < count) {
+               applet_fl_set(appctx, APPCTX_FL_INBLK_FULL);
+               TRACE_STATE("report appctx inbuf is full", APPLET_EV_SEND|APPLET_EV_BLK, appctx);
+       }
        return ret;
 }
 
 size_t appctx_raw_snd_buf(struct appctx *appctx, struct buffer *buf, size_t count, unsigned flags)
 {
-       return b_xfer(&appctx->inbuf, buf, MIN(b_room(&appctx->inbuf), count));
+       size_t ret = 0;
+
+       ret = b_xfer(&appctx->inbuf, buf, MIN(b_room(&appctx->inbuf), count));
+       if (ret < count) {
+               applet_fl_set(appctx, APPCTX_FL_INBLK_FULL);
+               TRACE_STATE("report appctx inbuf is full", APPLET_EV_SEND|APPLET_EV_BLK, appctx);
+       }
+  end:
+       return ret;
 }
 
 size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsigned int flags)
@@ -616,21 +627,16 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig
        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)) {
                applet_fl_set(appctx, APPCTX_FL_INBLK_ALLOC);
                TRACE_STATE("waiting for appctx inbuf allocation", APPLET_EV_SEND|APPLET_EV_BLK, appctx);
                goto end;
        }
 
-       if (!count)
-               goto end;
-
        ret = appctx->applet->snd_buf(appctx, buf, count, flags);
-       if (ret < count) {
-               applet_fl_set(appctx, APPCTX_FL_INBLK_FULL);
-               appctx_wakeup(appctx);
-               TRACE_STATE("report appctx inbuf is full", APPLET_EV_SEND|APPLET_EV_BLK, appctx);
-       }
 
   end:
        if (applet_fl_test(appctx, (APPCTX_FL_ERROR|APPCTX_FL_ERR_PENDING))) {