Skip to content

Commit f32f0e5

Browse files
committed
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.
1 parent 919c2ae commit f32f0e5

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/resolve/resolved-dns-transaction.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ static void dns_transaction_reset_answer(DnsTransaction *t) {
4040
t->answer_authenticated = false;
4141
}
4242

43+
static void dns_transaction_close_connection(DnsTransaction *t) {
44+
assert(t);
45+
46+
t->stream = dns_stream_free(t->stream);
47+
t->dns_udp_event_source = sd_event_source_unref(t->dns_udp_event_source);
48+
t->dns_udp_fd = safe_close(t->dns_udp_fd);
49+
}
50+
4351
DnsTransaction* dns_transaction_free(DnsTransaction *t) {
4452
DnsQueryCandidate *c;
4553
DnsZoneItem *i;
@@ -49,15 +57,12 @@ DnsTransaction* dns_transaction_free(DnsTransaction *t) {
4957
return NULL;
5058

5159
sd_event_source_unref(t->timeout_event_source);
60+
dns_transaction_close_connection(t);
5261

5362
dns_packet_unref(t->sent);
5463
dns_transaction_reset_answer(t);
5564

56-
sd_event_source_unref(t->dns_udp_event_source);
57-
safe_close(t->dns_udp_fd);
58-
5965
dns_server_unref(t->server);
60-
dns_stream_free(t->stream);
6166

6267
if (t->scope) {
6368
hashmap_remove_value(t->scope->transactions_by_key, t->key, t);
@@ -259,6 +264,7 @@ void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state) {
259264

260265
t->state = state;
261266

267+
dns_transaction_close_connection(t);
262268
dns_transaction_stop(t);
263269

264270
/* Notify all queries that are interested, but make sure the

src/resolve/resolved-dns-transaction.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,19 @@ struct DnsTransaction {
100100
sd_event_source *timeout_event_source;
101101
unsigned n_attempts;
102102

103+
/* UDP connection logic, if we need it */
103104
int dns_udp_fd;
104105
sd_event_source *dns_udp_event_source;
105106

107+
/* TCP connection logic, if we need it */
108+
DnsStream *stream;
109+
106110
/* The active server */
107111
DnsServer *server;
108112

109113
/* The features of the DNS server at time of transaction start */
110114
DnsServerFeatureLevel current_features;
111115

112-
/* TCP connection logic, if we need it */
113-
DnsStream *stream;
114-
115116
/* Query candidates this transaction is referenced by and that
116117
* shall be notified about this specific transaction
117118
* completing. */

0 commit comments

Comments
 (0)