resolved: split dns_transaction_go()

Split some code out of dns_transaction_go() so we can re-use it later from
different context. The new function dns_transaction_prepare_next_attempt()
takes care of preparing everything so that a new packet can conditionally
be formulated for a transaction.

This patch shouldn't cause any functional change.
This commit is contained in:
Daniel Mack 2015-11-30 19:06:36 +01:00
parent 547493c5ad
commit 1effe96568
1 changed files with 20 additions and 9 deletions

View File

@ -675,9 +675,8 @@ static usec_t transaction_get_resend_timeout(DnsTransaction *t) {
}
}
int dns_transaction_go(DnsTransaction *t) {
static int dns_transaction_prepare_next_attempt(DnsTransaction *t, usec_t ts) {
bool had_stream;
usec_t ts;
int r;
assert(t);
@ -686,11 +685,6 @@ int dns_transaction_go(DnsTransaction *t) {
dns_transaction_stop(t);
log_debug("Excercising transaction on scope %s on %s/%s",
dns_protocol_to_string(t->scope->protocol),
t->scope->link ? t->scope->link->name : "*",
t->scope->family == AF_UNSPEC ? "*" : af_to_name(t->scope->family));
if (t->n_attempts >= TRANSACTION_ATTEMPTS_MAX(t->scope->protocol)) {
dns_transaction_complete(t, DNS_TRANSACTION_ATTEMPTS_MAX_REACHED);
return 0;
@ -703,8 +697,6 @@ int dns_transaction_go(DnsTransaction *t) {
return 0;
}
assert_se(sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &ts) >= 0);
t->n_attempts++;
t->start_usec = ts;
t->received = dns_packet_unref(t->received);
@ -767,6 +759,25 @@ int dns_transaction_go(DnsTransaction *t) {
}
}
return 1;
}
int dns_transaction_go(DnsTransaction *t) {
usec_t ts;
int r;
assert(t);
assert_se(sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &ts) >= 0);
r = dns_transaction_prepare_next_attempt(t, ts);
if (r <= 0)
return r;
log_debug("Excercising transaction on scope %s on %s/%s",
dns_protocol_to_string(t->scope->protocol),
t->scope->link ? t->scope->link->name : "*",
t->scope->family == AF_UNSPEC ? "*" : af_to_name(t->scope->family));
if (!t->initial_jitter_scheduled &&
(t->scope->protocol == DNS_PROTOCOL_LLMNR ||
t->scope->protocol == DNS_PROTOCOL_MDNS)) {