Changeset ee0e95f in code for dns.c


Ignore:
Timestamp:
Mar 31, 2014, 2:14:10 PM (11 years ago)
Author:
Florian Obser <florian@…>
Branches:
master
Children:
dab4135
Parents:
cdd2ff5
Message:

new and public asr api; from eric@
OK mikeb

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dns.c

    rcdd2ff5 ree0e95f  
    2424#include <sys/time.h>
    2525#include <netinet/in.h>
     26#include <netdb.h>
    2627#include <errno.h>
    2728#include <event.h>
     
    3132#include <syslog.h>
    3233
    33 #include "asr.h"
     34#include <asr.h>
    3435
    3536#include "icb.h"
     
    3738
    3839struct async_event;
    39 struct async_event *async_run_event(struct async *,
    40     void (*)(int, struct async_res *, void *), void *);
    41 void dns_done(int, struct async_res *, void *);
     40struct async_event *async_run_event(struct asr_query *,
     41    void (*)(struct asr_result *, void *), void *);
     42void dns_done(struct asr_result *, void *);
    4243
    4344extern int dodns;
    4445
    4546void
    46 dns_done(int ev __attribute__((__unused__)), struct async_res *ar, void *arg)
     47dns_done(struct asr_result *ar, void *arg)
    4748{
    4849        struct icb_session *is = arg;
     
    6465dns_rresolv(struct icb_session *is, struct sockaddr *sa)
    6566{
    66         struct async *as;
     67        struct asr_query *as;
    6768
    6869        if (!dodns)
     
    8081
    8182struct async_event {
    82         struct async    *async;
     83        struct asr_query *async;
    8384        struct event     ev;
    84         void            (*callback)(int, struct async_res *, void *);
     85        void            (*callback)(struct asr_result *, void *);
    8586        void            *arg;
    8687};
     
    8990
    9091struct async_event *
    91 async_run_event(struct async * async,
    92     void (*cb)(int, struct async_res *, void *), void *arg)
     92async_run_event(struct asr_query *async,
     93    void (*cb)(struct asr_result *, void *), void *arg)
    9394{
    9495        struct async_event      *aev;
     
    113114{
    114115        struct async_event      *aev = arg;
    115         struct async_res         ar;
    116         int                      r;
     116        struct asr_result        ar;
    117117        struct timeval           tv;
    118118
    119         while ((r = asr_async_run(aev->async, &ar)) == ASYNC_YIELD)
    120                 aev->callback(r, &ar, aev->arg);
     119        event_del(&aev->ev);
    121120
    122         event_del(&aev->ev);
    123         if (r == ASYNC_COND) {
     121        if (asr_run(aev->async, &ar) == 0) {
    124122                event_set(&aev->ev, ar.ar_fd,
    125                           ar.ar_cond == ASYNC_READ ? EV_READ : EV_WRITE,
    126                           async_event_dispatch, aev);
     123                    ar.ar_cond == ASR_WANT_READ ? EV_READ : EV_WRITE,
     124                    async_event_dispatch, aev);
    127125                tv.tv_sec = ar.ar_timeout / 1000;
    128126                tv.tv_usec = (ar.ar_timeout % 1000) * 1000;
    129127                event_add(&aev->ev, &tv);
    130         } else { /* ASYNC_DONE */
    131                 aev->callback(r, &ar, aev->arg);
     128        } else { /* done */
     129                aev->callback(&ar, aev->arg);
    132130                free(aev);
    133131        }
Note: See TracChangeset for help on using the changeset viewer.