diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-01-21 17:03:27 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-01-21 17:03:27 +0000 |
commit | b6b05333337350a9ad9936f1443048e7bd3a56fc (patch) | |
tree | f4d7d60632602281c905e7e9020cb4ab94ab696e /src/lua/lua_udp.c | |
parent | 7957fc516a137f4eabab2fbacd30d4ecd99afc8d (diff) | |
download | rspamd-b6b05333337350a9ad9936f1443048e7bd3a56fc.tar.gz rspamd-b6b05333337350a9ad9936f1443048e7bd3a56fc.zip |
[Minor] Lua_udp: Fix various issues
Diffstat (limited to 'src/lua/lua_udp.c')
-rw-r--r-- | src/lua/lua_udp.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/lua/lua_udp.c b/src/lua/lua_udp.c index 1bff702a9..c0bf7febb 100644 --- a/src/lua/lua_udp.c +++ b/src/lua/lua_udp.c @@ -109,6 +109,10 @@ lua_udp_cbd_fin (gpointer p) struct lua_udp_cbdata *cbd = (struct lua_udp_cbdata *)p; if (cbd->sock != -1) { + if (rspamd_event_pending (&cbd->io, EV_READ|EV_WRITE)) { + event_del (&cbd->io); + } + close (cbd->sock); } @@ -228,7 +232,7 @@ lua_udp_push_data (struct lua_udp_cbdata *cbd, const gchar *data, static gboolean lua_udp_maybe_register_event (struct lua_udp_cbdata *cbd) { - if (cbd->s) { + if (cbd->s && !cbd->async_ev) { cbd->async_ev = rspamd_session_add_event (cbd->s, lua_udp_cbd_fin, cbd, M); @@ -237,7 +241,7 @@ lua_udp_maybe_register_event (struct lua_udp_cbdata *cbd) } } - if (cbd->task) { + if (cbd->task && !cbd->item) { cbd->item = rspamd_symcache_get_cur_item (cbd->task); rspamd_symcache_item_async_inc (cbd->task, cbd->item, M); } @@ -254,8 +258,10 @@ lua_udp_io_handler (gint fd, short what, gpointer p) L = cbd->L; + event_del (&cbd->io); + if (what == EV_TIMEOUT) { - if (cbd->sent && cbd->retransmits > 0) { + if (cbd->sent && cbd->retransmits > 0) { r = lua_try_send_request (cbd); if (r == RSPAMD_SENT_OK) { @@ -263,6 +269,7 @@ lua_udp_io_handler (gint fd, short what, gpointer p) event_base_set (cbd->ev_base, &cbd->io); event_add (&cbd->io, &cbd->tv); lua_udp_maybe_register_event (cbd); + cbd->retransmits --; } else if (r == RSPAMD_SENT_FAILURE) { lua_udp_maybe_push_error (cbd, "write error"); @@ -445,7 +452,7 @@ lua_udp_sendto (lua_State *L) { lua_pushstring (L, "timeout"); lua_gettable (L, -2); if (lua_type (L, -1) == LUA_TNUMBER) { - timeout = lua_tonumber (L, -1) * 1000.; + timeout = lua_tonumber (L, -1); } lua_pop (L, 1); |