summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-12-26 14:53:17 +0100
committerLennart Poettering <lennart@poettering.net>2015-12-27 01:41:39 +0100
commitf32f0e57ca117455fb24ca72238c4958cd800b28 (patch)
treeb181e0d09c970b4f5848099ce1aa01913d27bbce
parent919c2ae05c829de6a2a478341c7133ccb5f594f1 (diff)
resolved: add dns_transaction_close_connection()
This new call unifies how we shut down all connection resources, such as UDP sockets, event sources, and TCP stream objects. This patch just adds the basic hook-up, this function will be used more in later commits.
-rw-r--r--src/resolve/resolved-dns-transaction.c14
-rw-r--r--src/resolve/resolved-dns-transaction.h7
2 files changed, 14 insertions, 7 deletions
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index ba1f8cc7af..cf7dae0e69 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -40,6 +40,14 @@ static void dns_transaction_reset_answer(DnsTransaction *t) {
t->answer_authenticated = false;
}
+static void dns_transaction_close_connection(DnsTransaction *t) {
+ assert(t);
+
+ t->stream = dns_stream_free(t->stream);
+ t->dns_udp_event_source = sd_event_source_unref(t->dns_udp_event_source);
+ t->dns_udp_fd = safe_close(t->dns_udp_fd);
+}
+
DnsTransaction* dns_transaction_free(DnsTransaction *t) {
DnsQueryCandidate *c;
DnsZoneItem *i;
@@ -49,15 +57,12 @@ DnsTransaction* dns_transaction_free(DnsTransaction *t) {
return NULL;
sd_event_source_unref(t->timeout_event_source);
+ dns_transaction_close_connection(t);
dns_packet_unref(t->sent);
dns_transaction_reset_answer(t);
- sd_event_source_unref(t->dns_udp_event_source);
- safe_close(t->dns_udp_fd);
-
dns_server_unref(t->server);
- dns_stream_free(t->stream);
if (t->scope) {
hashmap_remove_value(t->scope->transactions_by_key, t->key, t);
@@ -259,6 +264,7 @@ void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state) {
t->state = state;
+ dns_transaction_close_connection(t);
dns_transaction_stop(t);
/* Notify all queries that are interested, but make sure the
diff --git a/src/resolve/resolved-dns-transaction.h b/src/resolve/resolved-dns-transaction.h
index a351a5043b..faf3ce6fb9 100644
--- a/src/resolve/resolved-dns-transaction.h
+++ b/src/resolve/resolved-dns-transaction.h
@@ -100,18 +100,19 @@ struct DnsTransaction {
sd_event_source *timeout_event_source;
unsigned n_attempts;
+ /* UDP connection logic, if we need it */
int dns_udp_fd;
sd_event_source *dns_udp_event_source;
+ /* TCP connection logic, if we need it */
+ DnsStream *stream;
+
/* The active server */
DnsServer *server;
/* The features of the DNS server at time of transaction start */
DnsServerFeatureLevel current_features;
- /* TCP connection logic, if we need it */
- DnsStream *stream;
-
/* Query candidates this transaction is referenced by and that
* shall be notified about this specific transaction
* completing. */