MINOR: buffer: use b_room() to determine available space in a buffer
We used to have variations around buffer_total_space() and
size-buffer_len() or size-b_data(). Let's simplify all this. buffer_len()
was also removed as not used anymore.
diff --git a/src/hlua.c b/src/hlua.c
index 7976242..e784682 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2025,7 +2025,7 @@
}
/* Check for avalaible space. */
- len = buffer_total_space(s->req.buf);
+ len = b_room(s->req.buf);
if (len <= 0) {
goto hlua_socket_write_yield_return;
}
@@ -2925,7 +2925,7 @@
WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_append_yield, TICK_ETERNITY, 0));
}
- max = channel_recv_limit(chn) - buffer_len(chn->buf);
+ max = channel_recv_limit(chn) - b_data(chn->buf);
if (max > len - l)
max = len - l;
@@ -2943,7 +2943,7 @@
lua_pushinteger(L, l);
hlua_resynchonize_proto(chn_strm(chn), !!(chn->flags & CF_ISRESP));
- max = channel_recv_limit(chn) - buffer_len(chn->buf);
+ max = channel_recv_limit(chn) - b_data(chn->buf);
if (max == 0 && 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,
@@ -3024,7 +3024,7 @@
* The reserve is guaranted for the processing of incoming
* data, because the buffer will be flushed.
*/
- max = chn->buf->size - buffer_len(chn->buf);
+ max = b_room(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,
@@ -3059,7 +3059,7 @@
* in this case, we cannot add more data, so we cannot yield,
* we return the amount of copyied data.
*/
- max = chn->buf->size - buffer_len(chn->buf);
+ max = b_room(chn->buf);
if (max == 0 && chn->buf->o == 0)
return 1;
@@ -3177,9 +3177,7 @@
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 = b_room(chn->buf);
rem -= global.tune.maxrewrite; /* Rewrite reserved size */
lua_pushboolean(L, rem <= 0);