mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-17 17:04:35 +00:00
BUG/MEDIUM: lua: many errors when we try to send data with the channel API
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.
This commit is contained in:
parent
53e08ecc41
commit
deb5d73883
38
src/hlua.c
38
src/hlua.c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user