summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2011-03-27 18:08:22 +0000
committerEric Faurot <eric@cvs.openbsd.org>2011-03-27 18:08:22 +0000
commit449821bc471a073d5ee4f3117e45d0200c27a1a7 (patch)
tree4b2b6ad0c29ada2487d89c3da0eddc973e4d7ae1
parent2317fa77ecd8fba489355fad49f81a9b25b1361a (diff)
add a function to factorize resetting of dnssession events.
ok gilles@
-rw-r--r--usr.sbin/smtpd/dns.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c
index e40b7a9dbe3..2c776891b21 100644
--- a/usr.sbin/smtpd/dns.c
+++ b/usr.sbin/smtpd/dns.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dns.c,v 1.34 2011/03/26 21:40:14 eric Exp $ */
+/* $OpenBSD: dns.c,v 1.35 2011/03/27 18:08:21 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -45,6 +45,7 @@
struct dnssession *dnssession_init(struct smtpd *, struct dns *);
void dnssession_destroy(struct smtpd *, struct dnssession *);
void dnssession_mx_insert(struct dnssession *, struct mx *);
+void dns_asr_event_set(struct dnssession *, struct asr_result *, void(*)(int, short, void*));
void dns_asr_handler(int, short, void *);
void dns_asr_mx_handler(int, short, void *);
void lookup_host(struct imsgev *, struct dns *, int, int);
@@ -151,6 +152,19 @@ noasr:
}
void
+dns_asr_event_set(struct dnssession *dnssession, struct asr_result *ar,
+ void (*handler)(int, short, void*))
+{
+ struct timeval tv = { 0, 0 };
+
+ tv.tv_usec = ar->ar_timeout * 1000;
+ event_set(&dnssession->ev, ar->ar_fd,
+ ar->ar_cond == ASR_READ ? EV_READ : EV_WRITE,
+ handler, dnssession);
+ event_add(&dnssession->ev, &tv);
+}
+
+void
dns_asr_handler(int fd, short event, void *arg)
{
struct dnssession *dnssession = arg;
@@ -161,7 +175,6 @@ dns_asr_handler(int fd, short event, void *arg)
struct query q;
struct rr rr;
struct asr_result ar;
- struct timeval tv = { 0, 0 };
char *p;
int cnt;
int ret;
@@ -170,11 +183,7 @@ dns_asr_handler(int fd, short event, void *arg)
switch ((ret = asr_run(dnssession->aq, &ar))) {
case ASR_COND:
- tv.tv_usec = ar.ar_timeout * 1000;
- event_set(&dnssession->ev, ar.ar_fd,
- ar.ar_cond == ASR_READ ? EV_READ : EV_WRITE,
- dns_asr_handler, dnssession);
- event_add(&dnssession->ev, &tv);
+ dns_asr_event_set(dnssession, &ar, dns_asr_handler);
return;
case ASR_YIELD:
@@ -309,16 +318,11 @@ dns_asr_mx_handler(int fd, short event, void *arg)
struct dns *query = &dnssession->query;
struct smtpd *env = query->env;
struct asr_result ar;
- struct timeval tv = { 0, 0 };
int ret;
switch ((ret = asr_run(dnssession->aq, &ar))) {
case ASR_COND:
- tv.tv_usec = ar.ar_timeout * 1000;
- event_set(&dnssession->ev, ar.ar_fd,
- ar.ar_cond == ASR_READ ? EV_READ : EV_WRITE,
- dns_asr_mx_handler, dnssession);
- event_add(&dnssession->ev, &tv);
+ dns_asr_event_set(dnssession, &ar, dns_asr_mx_handler);
return;
case ASR_YIELD: