Changeset dab4135 in code for dns.c


Ignore:
Timestamp:
Jun 17, 2014, 10:50:41 AM (11 years ago)
Author:
Florian Obser <florian@…>
Branches:
master
Children:
383d37b
Parents:
ee0e95f
Message:

Use libevent asr helpers; from eric@
"please commit them now" mikeb@

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dns.c

    ree0e95f rdab4135  
    11/*
    22 * Copyright (c) 2014 Mike Belopuhov
    3  *
    4  * ASR implementation and OpenSMTPD integration are copyright
    5  * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
    6  * Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net>
    7  * Copyright (c) 2011-2012 Eric Faurot <eric@faurot.net>
     3 * Copyright (c) 2014 Eric Faurot <eric@faurot.net>
    84 *
    95 * Permission to use, copy, modify, and distribute this software for any
     
    3733#include "icbd.h"
    3834
    39 struct async_event;
    40 struct async_event *async_run_event(struct asr_query *,
    41     void (*)(struct asr_result *, void *), void *);
    4235void dns_done(struct asr_result *, void *);
    4336
     
    7568        as = getnameinfo_async(sa, sa->sa_len, is->hostname,
    7669            sizeof is->hostname, NULL, 0, NI_NOFQDN, NULL);
    77         async_run_event(as, dns_done, is);
     70        event_asr_run(as, dns_done, is);
    7871}
    79 
    80 /* Generic libevent glue for asr */
    81 
    82 struct async_event {
    83         struct asr_query *async;
    84         struct event     ev;
    85         void            (*callback)(struct asr_result *, void *);
    86         void            *arg;
    87 };
    88 
    89 void async_event_dispatch(int, short, void *);
    90 
    91 struct async_event *
    92 async_run_event(struct asr_query *async,
    93     void (*cb)(struct asr_result *, void *), void *arg)
    94 {
    95         struct async_event      *aev;
    96         struct timeval           tv;
    97 
    98         aev = calloc(1, sizeof *aev);
    99         if (aev == NULL)
    100                 return (NULL);
    101         aev->async = async;
    102         aev->callback = cb;
    103         aev->arg = arg;
    104         tv.tv_sec = 0;
    105         tv.tv_usec = 0;
    106         evtimer_set(&aev->ev, async_event_dispatch, aev);
    107         evtimer_add(&aev->ev, &tv);
    108         return (aev);
    109 }
    110 
    111 void
    112 async_event_dispatch(int fd __attribute__((__unused__)),
    113     short ev __attribute__((__unused__)), void *arg)
    114 {
    115         struct async_event      *aev = arg;
    116         struct asr_result        ar;
    117         struct timeval           tv;
    118 
    119         event_del(&aev->ev);
    120 
    121         if (asr_run(aev->async, &ar) == 0) {
    122                 event_set(&aev->ev, ar.ar_fd,
    123                     ar.ar_cond == ASR_WANT_READ ? EV_READ : EV_WRITE,
    124                     async_event_dispatch, aev);
    125                 tv.tv_sec = ar.ar_timeout / 1000;
    126                 tv.tv_usec = (ar.ar_timeout % 1000) * 1000;
    127                 event_add(&aev->ev, &tv);
    128         } else { /* done */
    129                 aev->callback(&ar, aev->arg);
    130                 free(aev);
    131         }
    132 }
Note: See TracChangeset for help on using the changeset viewer.