new and public asr api; from eric@

OK mikeb
This commit is contained in:
Florian Obser 2014-03-31 16:14:10 +02:00
parent cdd2ff5fd2
commit ee0e95fea0
2 changed files with 18 additions and 23 deletions

View File

@ -10,9 +10,6 @@ CFLAGS+= -W -Wall -Werror
CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare
# hook up asynchronous resolver
CFLAGS+= -I${BSDSRCDIR}/lib/libc/asr
DPADD= ${LIBEVENT}
LDADD= -levent

38
dns.c
View File

@ -23,6 +23,7 @@
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include <event.h>
#include <resolv.h>
@ -30,20 +31,20 @@
#include <string.h>
#include <syslog.h>
#include "asr.h"
#include <asr.h>
#include "icb.h"
#include "icbd.h"
struct async_event;
struct async_event *async_run_event(struct async *,
void (*)(int, struct async_res *, void *), void *);
void dns_done(int, struct async_res *, void *);
struct async_event *async_run_event(struct asr_query *,
void (*)(struct asr_result *, void *), void *);
void dns_done(struct asr_result *, void *);
extern int dodns;
void
dns_done(int ev __attribute__((__unused__)), struct async_res *ar, void *arg)
dns_done(struct asr_result *ar, void *arg)
{
struct icb_session *is = arg;
@ -63,7 +64,7 @@ dns_done(int ev __attribute__((__unused__)), struct async_res *ar, void *arg)
void
dns_rresolv(struct icb_session *is, struct sockaddr *sa)
{
struct async *as;
struct asr_query *as;
if (!dodns)
return;
@ -79,17 +80,17 @@ dns_rresolv(struct icb_session *is, struct sockaddr *sa)
/* Generic libevent glue for asr */
struct async_event {
struct async *async;
struct asr_query *async;
struct event ev;
void (*callback)(int, struct async_res *, void *);
void (*callback)(struct asr_result *, void *);
void *arg;
};
void async_event_dispatch(int, short, void *);
struct async_event *
async_run_event(struct async * async,
void (*cb)(int, struct async_res *, void *), void *arg)
async_run_event(struct asr_query *async,
void (*cb)(struct asr_result *, void *), void *arg)
{
struct async_event *aev;
struct timeval tv;
@ -112,23 +113,20 @@ async_event_dispatch(int fd __attribute__((__unused__)),
short ev __attribute__((__unused__)), void *arg)
{
struct async_event *aev = arg;
struct async_res ar;
int r;
struct asr_result ar;
struct timeval tv;
while ((r = asr_async_run(aev->async, &ar)) == ASYNC_YIELD)
aev->callback(r, &ar, aev->arg);
event_del(&aev->ev);
if (r == ASYNC_COND) {
if (asr_run(aev->async, &ar) == 0) {
event_set(&aev->ev, ar.ar_fd,
ar.ar_cond == ASYNC_READ ? EV_READ : EV_WRITE,
async_event_dispatch, aev);
ar.ar_cond == ASR_WANT_READ ? EV_READ : EV_WRITE,
async_event_dispatch, aev);
tv.tv_sec = ar.ar_timeout / 1000;
tv.tv_usec = (ar.ar_timeout % 1000) * 1000;
event_add(&aev->ev, &tv);
} else { /* ASYNC_DONE */
aev->callback(r, &ar, aev->arg);
} else { /* done */
aev->callback(&ar, aev->arg);
free(aev);
}
}