aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_tcp.c
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2016-10-27 12:11:49 +0200
committerAndrew Lewis <nerf@judo.za.org>2016-10-27 13:02:39 +0200
commit4d473d78e3d50d0d57ebf518459da5aacb184797 (patch)
tree57766cdf90cb3c5c7fb1bd92598182285179a3b4 /src/lua/lua_tcp.c
parentfa1e7f8425a07af47cbf91711a36657aad89f623 (diff)
downloadrspamd-4d473d78e3d50d0d57ebf518459da5aacb184797.tar.gz
rspamd-4d473d78e3d50d0d57ebf518459da5aacb184797.zip
[Feature] Support requests without reads in lua_tcp
Diffstat (limited to 'src/lua/lua_tcp.c')
-rw-r--r--src/lua/lua_tcp.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c
index 391fb788a..a6cbf1f42 100644
--- a/src/lua/lua_tcp.c
+++ b/src/lua/lua_tcp.c
@@ -99,6 +99,7 @@ struct lua_tcp_cbdata {
guint16 port;
gboolean partial;
gboolean do_shutdown;
+ gboolean do_read;
gboolean connected;
};
@@ -288,15 +289,21 @@ call_finish_handler:
shutdown (cbd->fd, SHUT_WR);
}
- event_del (&cbd->ev);
+ if (cbd->do_read) {
+ event_del (&cbd->ev);
#ifdef EV_CLOSED
- event_set (&cbd->ev, cbd->fd, EV_READ|EV_PERSIST|EV_CLOSED,
- lua_tcp_handler, cbd);
+ event_set (&cbd->ev, cbd->fd, EV_READ|EV_PERSIST|EV_CLOSED,
+ lua_tcp_handler, cbd);
#else
- event_set (&cbd->ev, cbd->fd, EV_READ|EV_PERSIST, lua_tcp_handler, cbd);
+ event_set (&cbd->ev, cbd->fd, EV_READ|EV_PERSIST, lua_tcp_handler, cbd);
#endif
- event_base_set (cbd->ev_base, &cbd->ev);
- event_add (&cbd->ev, &cbd->tv);
+ event_base_set (cbd->ev_base, &cbd->ev);
+ event_add (&cbd->ev, &cbd->tv);
+ }
+ else {
+ lua_tcp_push_data (cbd, cbd->in->data, cbd->in->len);
+ REF_RELEASE (cbd);
+ }
}
static void
@@ -546,7 +553,7 @@ lua_tcp_request (lua_State *L)
struct iovec *iov = NULL;
guint niov = 0, total_out;
gdouble timeout = default_tcp_timeout;
- gboolean partial = FALSE, do_shutdown = FALSE;
+ gboolean partial = FALSE, do_shutdown = FALSE, do_read = TRUE;
if (lua_type (L, 1) == LUA_TTABLE) {
lua_pushstring (L, "host");
@@ -661,6 +668,13 @@ lua_tcp_request (lua_State *L)
}
lua_pop (L, 1);
+ lua_pushstring (L, "read");
+ lua_gettable (L, -2);
+ if (lua_type (L, -1) == LUA_TBOOLEAN) {
+ do_read = lua_toboolean (L, -1);
+ }
+ lua_pop (L, 1);
+
lua_pushstring (L, "on_connect");
lua_gettable (L, -2);