From: Thierry FOURNIER / OZON.IO Date: Mon, 7 Nov 2016 14:28:40 +0000 (+0100) Subject: MINOR: lua: add function which return true if the channel is full. X-Git-Tag: v1.7.0~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65192f35d226d09a18ca7d3f63e75e40ee310505;p=thirdparty%2Fhaproxy.git MINOR: lua: add function which return true if the channel is full. Add function which return true if the channel is full. It is useful for triggering some process when the buffer is full. --- diff --git a/doc/lua-api/_static/channel.fig b/doc/lua-api/_static/channel.fig index 0838a37cd1..8a6c0a1364 100644 --- a/doc/lua-api/_static/channel.fig +++ b/doc/lua-api/_static/channel.fig @@ -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 diff --git a/doc/lua-api/_static/channel.png b/doc/lua-api/_static/channel.png index 79eb6f78df..e12a26e819 100644 Binary files a/doc/lua-api/_static/channel.png and b/doc/lua-api/_static/channel.png differ diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index c42b2f3085..77c22662c9 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -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: diff --git a/src/hlua.c b/src/hlua.c index 121c283f1c..db023f58cb 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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);