.. js:function:: Channel.may_recv(channel)
- This function returns true if the channel may still receive data.
+ This function returns true if the channel may still receive data. When
+ called by a filter, the result is relative to the data visible by this
+ filter: if an earlier filter holds back some data, the function always
+ returns true, even if the input is closed, because the held data may still
+ be received by the current filter.
:param class_channel channel: The manipulated Channel.
:returns: a boolean
.. js:function:: HTTPMessage.set_eom(http_msg)
- This function set the end of message for the HTTP message **http_msg**.
+ This function set the end of message for the HTTP message **http_msg**. It
+ can only be called when all data of the message are visible by the current
+ filter. Otherwise, an error is raised, because an earlier filter holding
+ data back may already have reached the end of the message, or may expose
+ data after it.
:param class_httpmessage http_msg: The manipulated HTTP message.
.. js:function:: HTTPMessage.unset_eom(http_msg)
This function remove the end of message for the HTTP message **http_msg**.
+ It can only be called when all data of the message are visible by the
+ current filter. Otherwise, an error is raised, because an earlier filter
+ holding data back may expose data carrying the end of message, which could
+ not be removed.
:param class_httpmessage http_msg: The manipulated HTTP message.
return filter;
}
+/* Helper function to know if all data in a channel are visible by the
+ * current filter. Returns 1 if no filter are attached to the channel or if
+ * all input data are visible by the filter. Otherwise 0 is returned.
+ */
+static int hlua_channel_fully_visible(lua_State *L, struct channel *chn)
+{
+ size_t offset = co_data(chn);
+ size_t len = ci_data(chn);
+
+ hlua_channel_filter(L, 1, chn, &offset, &len);
+ return (offset + len == c_data(chn));
+}
+
/* Copies <len> bytes of data present in the channel's buffer, starting at the
* offset <offset>, and put it in a LUA string variable. It is the caller
* responsibility to ensure <len> and <offset> are valid. It always return the
__LJMP static int hlua_channel_may_recv(lua_State *L)
{
struct channel *chn;
+ int may_recv;
MAY_LJMP(check_args(L, 1, "may_recv"));
chn = MAY_LJMP(hlua_checkchannel(L, 1));
- lua_pushboolean(L, (!channel_input_closed(chn) && channel_may_recv(chn)));
+ may_recv = !hlua_channel_fully_visible(L, chn) || (!channel_input_closed(chn) &&
+ channel_may_recv(chn));
+
+ lua_pushboolean(L, may_recv);
return 1;
}