]> source.dussan.org Git - rspamd.git/commitdiff
Fix up another event related problem.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 25 Jul 2011 21:37:38 +0000 (01:37 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 25 Jul 2011 21:37:38 +0000 (01:37 +0400)
src/dns.c
src/plugins/fuzzy_check.c

index 5148e742b7d75eed4a881f00c0840bfc730b27a7..2f5e99e388df6c23c615a8d01a06c4d013669756 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -539,7 +539,6 @@ send_dns_request (struct rspamd_dns_request *req)
        r = send (req->sock, req->packet, req->pos, 0);
        if (r == -1) {
                if (errno == EAGAIN) {
-                       event_del (&req->io_event);
                        event_set (&req->io_event, req->sock, EV_WRITE, dns_retransmit_handler, req);
                        event_add (&req->io_event, &req->tv);
                        register_async_event (req->session, (event_finalizer_t)event_del, &req->io_event, FALSE);
@@ -552,7 +551,6 @@ send_dns_request (struct rspamd_dns_request *req)
                }
        }
        else if (r < req->pos) {
-               event_del (&req->io_event);
                event_set (&req->io_event, req->sock, EV_WRITE, dns_retransmit_handler, req);
                event_add (&req->io_event, &req->tv);
                register_async_event (req->session, (event_finalizer_t)event_del, &req->io_event, FALSE);
@@ -1086,7 +1084,6 @@ dns_timer_cb (gint fd, short what, void *arg)
        evtimer_add (&req->timer_event, &req->tv);
        r = send_dns_request (req);
        if (r == -1) {
-               event_del (&req->io_event);
                rep = memory_pool_alloc0 (req->pool, sizeof (struct rspamd_dns_reply));
                rep->request = req;
                rep->code = DNS_RC_SERVFAIL;
@@ -1107,9 +1104,9 @@ dns_retransmit_handler (gint fd, short what, void *arg)
        if (what == EV_WRITE) {
                /* Retransmit dns request */
                req->retransmits ++;
+               event_del (&req->io_event);
                if (req->retransmits >= req->resolver->max_retransmits) {
                        msg_err ("maximum number of retransmits expired for %s", req->requested_name);
-                       event_del (&req->io_event);
                        rep = memory_pool_alloc0 (req->pool, sizeof (struct rspamd_dns_reply));
                        rep->request = req;
                        rep->code = DNS_RC_SERVFAIL;
@@ -1123,7 +1120,6 @@ dns_retransmit_handler (gint fd, short what, void *arg)
                }
                r = send_dns_request (req);
                if (r == -1) {
-                       event_del (&req->io_event);
                        rep = memory_pool_alloc0 (req->pool, sizeof (struct rspamd_dns_reply));
                        rep->request = req;
                        rep->code = DNS_RC_SERVFAIL;
@@ -1227,13 +1223,13 @@ make_dns_request (struct rspamd_dns_resolver *resolver,
 
        /* Fill timeout */
        msec_to_tv (resolver->request_timeout, &req->tv);
+       evtimer_set (&req->timer_event, dns_timer_cb, req);
        
        /* Now send request to server */
        r = send_dns_request (req);
 
        if (r == 1) {
                /* Add timer event */
-               evtimer_set (&req->timer_event, dns_timer_cb, req);
                evtimer_add (&req->timer_event, &req->tv);
 
                /* Add request to hash table */
index eafbbeb903d40dccbd51aeb95e02d972423cab2f..30e58fa450f1e3edcc1d8d16f24660d3efe7c74e 100644 (file)
@@ -474,6 +474,7 @@ fuzzy_io_callback (gint fd, short what, void *arg)
                        goto err;
                }
                else {
+                       event_del (&session->ev);
                        event_set (&session->ev, fd, EV_READ, fuzzy_io_callback, session);
                        event_add (&session->ev, &session->tv);
                }
@@ -559,6 +560,7 @@ fuzzy_learn_callback (gint fd, short what, void *arg)
                        goto err;
                }
                else {
+                       event_del (&session->ev);
                        event_set (&session->ev, fd, EV_READ, fuzzy_learn_callback, session);
                        event_add (&session->ev, &session->tv);
                }