From 4d473d78e3d50d0d57ebf518459da5aacb184797 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Thu, 27 Oct 2016 12:11:49 +0200 Subject: [PATCH] [Feature] Support requests without reads in lua_tcp --- src/lua/lua_tcp.c | 28 +++++++++++++++++++++------- 1 file 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); -- 2.39.5