]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: add function which return true if the channel is full.
authorThierry FOURNIER / OZON.IO <thierry.fournier@ozon.io>
Mon, 7 Nov 2016 14:28:40 +0000 (15:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 12 Nov 2016 09:42:25 +0000 (10:42 +0100)
Add function which return true if the channel is full. It is
useful for triggering some process when the buffer is full.

doc/lua-api/_static/channel.fig
doc/lua-api/_static/channel.png
doc/lua-api/index.rst
src/hlua.c

index 0838a37cd1d36e006e55e653ac0294899c32b822..8a6c0a136418eaff37c02e8df98e03266b89f7d2 100644 (file)
@@ -8,12 +8,12 @@ Single
 -2
 1200 2
 1 1 0 1 0 7 50 -1 -1 0.000 1 0.0000 4500 1620 1260 585 4500 1620 5760 2205
-2 3 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 9
+2 3 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 8
         1170 1350 1170 1890 2790 1890 2790 2070 3240 1620 2790 1170
-        2790 1350 1170 1350 1170 1350
-2 3 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 9
+        2790 1350 1170 1350
+2 3 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 8
         5760 1350 5760 1890 7380 1890 7380 2070 7830 1620 7380 1170
-        7380 1350 5760 1350 5760 1350
+        7380 1350 5760 1350
 2 1 1 1 0 7 50 -1 -1 1.000 0 0 -1 1 0 2
        5 1 1.00 60.00 120.00
         6210 540 6210 1440
@@ -51,4 +51,5 @@ Single
 4 0 0 50 -1 12 12 0.0000 4 150 720 6300 1110 send()\001
 4 0 0 50 -1 12 12 0.0000 4 165 1560 6255 2205 get_out_len()\001
 4 0 0 50 -1 16 12 0.0000 4 150 1230 6120 2520 read functions\001
-4 1 0 50 -1 16 12 0.0000 4 150 1650 4500 540 both side functions\001
+4 1 0 50 -1 16 12 0.0000 4 150 1650 4500 315 both side functions\001
+4 1 0 50 -1 12 12 0.0000 4 150 1080 4500 540 is_full()\001
index 79eb6f78df3b472b97d5baa4b89f4009c7b781a0..e12a26e819056622c808ba0e9c6536c2ccc05537 100644 (file)
Binary files a/doc/lua-api/_static/channel.png and b/doc/lua-api/_static/channel.png differ
index c42b2f3085a2d805ee36e7716324614bd8f2fdb5..77c22662c9119b0a4e9fb0fe02bd6ceb7284736d 100644 (file)
@@ -1070,6 +1070,11 @@ Channel class
   :param class_channel channel: The manipulated Channel.
   :param integer int: The amount of data which will be forwarded.
 
+.. js:function:: Channel.is_full(channel)
+
+  This function returns true if the buffer channel is full.
+
+  :returns: a boolean
 
 .. _http_class:
 
index 121c283f1c25bfdbaefee614a6a4d8c0aae4b9e7..db023f58cbca319e9b381136ffa7d3bd56377750 100644 (file)
@@ -2859,6 +2859,24 @@ __LJMP static int hlua_channel_get_in_len(lua_State *L)
        return 1;
 }
 
+/* Returns true if the channel is full. */
+__LJMP static int hlua_channel_is_full(lua_State *L)
+{
+       struct channel *chn;
+       int rem;
+
+       MAY_LJMP(check_args(L, 1, "is_full"));
+       chn = MAY_LJMP(hlua_checkchannel(L, 1));
+
+       rem = chn->buf->size;
+       rem -= chn->buf->o; /* Output size */
+       rem -= chn->buf->i; /* Input size */
+       rem -= global.tune.maxrewrite; /* Rewrite reserved size */
+
+       lua_pushboolean(L, rem <= 0);
+       return 1;
+}
+
 /* Just returns the number of bytes available in the output
  * side of the buffer. This function never fails.
  */
@@ -6765,6 +6783,7 @@ void hlua_init(void)
        hlua_class_function(gL.T, "forward",     hlua_channel_forward);
        hlua_class_function(gL.T, "get_in_len",  hlua_channel_get_in_len);
        hlua_class_function(gL.T, "get_out_len", hlua_channel_get_out_len);
+       hlua_class_function(gL.T, "is_full",     hlua_channel_is_full);
 
        lua_rawset(gL.T, -3);