|
1 | 1 | local monotime = require "cqueues".monotime |
2 | 2 | local ca = require "cqueues.auxlib" |
3 | 3 | local cs = require "cqueues.socket" |
| 4 | +local cqueues_dns = require "cqueues.dns" |
4 | 5 | local cqueues_dns_record = require "cqueues.dns.record" |
5 | 6 | local http_tls = require "http.tls" |
6 | 7 | local http_util = require "http.util" |
@@ -125,25 +126,23 @@ local function connect(options, timeout) |
125 | 126 | local path = options.path |
126 | 127 | local host = options.host |
127 | 128 | if not path and not http_util.is_ip(host) then |
128 | | - local dns_resolver = options.dns_resolver |
129 | | - if dns_resolver then |
130 | | - local deadline = timeout and monotime()+timeout |
131 | | - local records = {} |
132 | | - if family == nil or family == cs.AF_UNSPEC then |
133 | | - dns_lookup(records, dns_resolver, host, cqueues_dns_record.AAAA, nil, timeout) |
134 | | - dns_lookup(records, dns_resolver, host, cqueues_dns_record.A, nil, deadline and deadline-monotime()) |
135 | | - elseif family == cs.AF_INET then |
136 | | - dns_lookup(records, dns_resolver, host, cqueues_dns_record.A, cqueues_dns_record.A, timeout) |
137 | | - elseif family == cs.AF_INET6 then |
138 | | - dns_lookup(records, dns_resolver, host, cqueues_dns_record.AAAA, cqueues_dns_record.AAAA, timeout) |
139 | | - end |
140 | | - local rec = records[1] |
141 | | - if not rec then |
142 | | - return nil, "The name does not resolve for the supplied parameters" |
143 | | - end |
144 | | - host = rec:addr() |
145 | | - timeout = deadline and deadline-monotime() |
| 129 | + local dns_resolver = options.dns_resolver or cqueues_dns.getpool() |
| 130 | + local deadline = timeout and monotime()+timeout |
| 131 | + local records = {} |
| 132 | + if family == nil or family == cs.AF_UNSPEC then |
| 133 | + dns_lookup(records, dns_resolver, host, cqueues_dns_record.AAAA, nil, timeout) |
| 134 | + dns_lookup(records, dns_resolver, host, cqueues_dns_record.A, nil, deadline and deadline-monotime()) |
| 135 | + elseif family == cs.AF_INET then |
| 136 | + dns_lookup(records, dns_resolver, host, cqueues_dns_record.A, cqueues_dns_record.A, timeout) |
| 137 | + elseif family == cs.AF_INET6 then |
| 138 | + dns_lookup(records, dns_resolver, host, cqueues_dns_record.AAAA, cqueues_dns_record.AAAA, timeout) |
| 139 | + end |
| 140 | + local rec = records[1] |
| 141 | + if not rec then |
| 142 | + return nil, "The name does not resolve for the supplied parameters" |
146 | 143 | end |
| 144 | + host = rec:addr() |
| 145 | + timeout = deadline and deadline-monotime() |
147 | 146 | end |
148 | 147 |
|
149 | 148 | local bind = options.bind |
|
0 commit comments