From 449821bc471a073d5ee4f3117e45d0200c27a1a7 Mon Sep 17 00:00:00 2001 From: Eric Faurot Date: Sun, 27 Mar 2011 18:08:22 +0000 Subject: add a function to factorize resetting of dnssession events. ok gilles@ --- usr.sbin/smtpd/dns.c | 30 +++++++++++++++++------------- 1 file 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 @@ -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); @@ -150,6 +151,19 @@ noasr: imsg_compose_event(asker, type, 0, 0, -1, query, sizeof(*query)); } +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) { @@ -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: -- cgit v1.2.3