]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: lua: many errors when we try to send data with the channel API
authorThierry FOURNIER <tfournier@exceliance.fr>
Fri, 6 Mar 2015 00:07:45 +0000 (01:07 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Mar 2015 16:47:52 +0000 (17:47 +0100)
First we allow to use the reserved size to write the data that
will be sent. The reserved size remain guaranty because the
writed data will be sent quickly and the reserved room we be
again avalaible.

This permits to guaranty that the function send always have
avalaible space to send data (except if it cannot connect to
the server).

The function buffer_replace2 works only on contiguous buffer.
This patch also detects if the required size is contiguous.
If it not the case we realign the buffer.

src/hlua.c

index 7f937f72ec0a1afbceffe397ab9db81d62bfeab6..40eedb5f9119a9e5986b7d2f2dd257df06583204 100644 (file)
@@ -2209,11 +2209,33 @@ __LJMP static int _hlua_channel_send(lua_State *L)
                }
        }
 
-       max = channel_recv_limit(chn->chn) - buffer_len(chn->chn->buf);
+       /* the writed data will be immediatly sent, so we can check
+        * the avalaible space without taking in account the reserve.
+        * The reserve is guaranted for the processing of incoming
+        * data, because the buffer will be flushed.
+        */
+       max = chn->chn->buf->size - buffer_len(chn->chn->buf);
+
+       /* If there are no space avalaible, and the output buffer is empty.
+        * in this case, we cannot add more data, so we cannot yield,
+        * we return the amount of copyied data.
+        */
+       if (max == 0 && chn->chn->buf->o == 0)
+               return 1;
+
+       /* Adjust the real required length. */
        if (max > len - l)
                max = len - l;
 
+       /* The buffer avalaible size may be not contiguous. This test
+        * detects a non contiguous buffer and realign it.
+        */
+       if (buffer_contig_space(chn->chn->buf) < max)
+               buffer_slow_realign(chn->chn->buf);
+
+       /* Copy input data in the buffer. */
        max = buffer_replace2(chn->chn->buf, chn->chn->buf->p, chn->chn->buf->p, str+l, max);
+
        /* buffer replace considers that the input part is filled.
         * so, I must forward these new data in the output part.
         */
@@ -2223,14 +2245,14 @@ __LJMP static int _hlua_channel_send(lua_State *L)
        lua_pop(L, 1);
        lua_pushinteger(L, l);
 
-       max = channel_recv_limit(chn->chn) - buffer_len(chn->chn->buf);
-       if (max == 0 && chn->chn->buf->o == 0) {
-               /* There are no space avalaible, and the output buffer is empty.
-                * in this case, we cannot add more data, so we cannot yield,
-                * we return the amount of copyied data.
-                */
+       /* If there are no space avalaible, and the output buffer is empty.
+        * in this case, we cannot add more data, so we cannot yield,
+        * we return the amount of copyied data.
+        */
+       max = chn->chn->buf->size - buffer_len(chn->chn->buf);
+       if (max == 0 && chn->chn->buf->o == 0)
                return 1;
-       }
+
        if (l < len) {
                /* If we are waiting for space in the response buffer, we
                 * must set the flag WAKERESWR. This flag required the task