struct lua_tcp_cbdata {
lua_State *L;
struct rspamd_async_session *session;
+ struct rspamd_async_event *async_ev;
struct event_base *ev_base;
struct timeval tv;
rspamd_inet_addr_t *addr;
static void
lua_tcp_maybe_free (struct lua_tcp_cbdata *cbd)
{
- if (cbd->session) {
+ if (cbd->async_ev) {
rspamd_session_watcher_pop (cbd->session, cbd->w);
rspamd_session_remove_event (cbd->session, lua_tcp_fin, cbd);
}
}
}
+static void
+lua_tcp_register_event (struct lua_tcp_cbdata *cbd)
+{
+ if (cbd->session) {
+ cbd->async_ev = rspamd_session_add_event (cbd->session,
+ (event_finalizer_t) lua_tcp_fin,
+ cbd,
+ g_quark_from_static_string ("lua tcp"));
+ cbd->w = rspamd_session_get_watcher (cbd->session);
+ rspamd_session_watcher_push (cbd->session);
+ }
+}
+
static gboolean
lua_tcp_make_connection (struct lua_tcp_cbdata *cbd)
{
struct event_base *ev_base;
struct lua_tcp_cbdata *cbd;
struct rspamd_dns_resolver *resolver;
- struct rspamd_async_session *session;
+ struct rspamd_async_session *session = NULL;
struct rspamd_task *task = NULL;
struct rspamd_config *cfg;
struct iovec *iov = NULL;
if (session) {
cbd->session = session;
- rspamd_session_add_event (session,
- (event_finalizer_t)lua_tcp_fin,
- cbd,
- g_quark_from_static_string ("lua tcp"));
- cbd->w = rspamd_session_get_watcher (session);
- rspamd_session_watcher_push (session);
}
if (rspamd_parse_inet_address (&cbd->addr, host, 0)) {
return 1;
}
+ else {
+ lua_tcp_register_event (cbd);
+ }
}
else {
if (task == NULL) {
RDNS_REQUEST_A, host)) {
lua_tcp_push_error (cbd, TRUE, "cannot resolve host: %s", host);
REF_RELEASE (cbd);
+ lua_pushboolean (L, FALSE);
+ return 1;
+ }
+ else {
+ lua_tcp_register_event (cbd);
}
}
else {
RDNS_REQUEST_A, host)) {
lua_tcp_push_error (cbd, TRUE, "cannot resolve host: %s", host);
REF_RELEASE (cbd);
+ lua_pushboolean (L, FALSE);
+ return 1;
+ }
+ else {
+ lua_tcp_register_event (cbd);
}
}
}