|
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" |
@@ -144,25 +145,23 @@ local function connect(options, timeout) |
144 | 145 | local path = options.path |
145 | 146 | local host = options.host |
146 | 147 | if not path and not http_util.is_ip(host) then |
147 | | - local dns_resolver = options.dns_resolver |
148 | | - if dns_resolver then |
149 | | - local deadline = timeout and monotime()+timeout |
150 | | - local records = {} |
151 | | - if family == nil or family == cs.AF_UNSPEC then |
152 | | - dns_lookup(dns_resolver, host, cqueues_dns_record.AAAA, nil, records, timeout) |
153 | | - dns_lookup(dns_resolver, host, cqueues_dns_record.A, nil, records, deadline and deadline-monotime()) |
154 | | - elseif family == cs.AF_INET then |
155 | | - dns_lookup(dns_resolver, host, cqueues_dns_record.A, cqueues_dns_record.A, records, timeout) |
156 | | - elseif family == cs.AF_INET6 then |
157 | | - dns_lookup(dns_resolver, host, cqueues_dns_record.AAAA, cqueues_dns_record.AAAA, records, timeout) |
158 | | - end |
159 | | - local rec = records[1] |
160 | | - if not rec then |
161 | | - return nil, "The name does not resolve for the supplied parameters" |
162 | | - end |
163 | | - host = rec:addr() |
164 | | - timeout = deadline and deadline-monotime() |
| 148 | + local dns_resolver = options.dns_resolver or cqueues_dns.getpool() |
| 149 | + local deadline = timeout and monotime()+timeout |
| 150 | + local records = {} |
| 151 | + if family == nil or family == cs.AF_UNSPEC then |
| 152 | + dns_lookup(dns_resolver, host, cqueues_dns_record.AAAA, nil, records, timeout) |
| 153 | + dns_lookup(dns_resolver, host, cqueues_dns_record.A, nil, records, deadline and deadline-monotime()) |
| 154 | + elseif family == cs.AF_INET then |
| 155 | + dns_lookup(dns_resolver, host, cqueues_dns_record.A, cqueues_dns_record.A, records, timeout) |
| 156 | + elseif family == cs.AF_INET6 then |
| 157 | + dns_lookup(dns_resolver, host, cqueues_dns_record.AAAA, cqueues_dns_record.AAAA, records, timeout) |
| 158 | + end |
| 159 | + local rec = records[1] |
| 160 | + if not rec then |
| 161 | + return nil, "The name does not resolve for the supplied parameters" |
165 | 162 | end |
| 163 | + host = rec:addr() |
| 164 | + timeout = deadline and deadline-monotime() |
166 | 165 | end |
167 | 166 |
|
168 | 167 | local s, err, errno = ca.fileresult(cs.connect { |
|
0 commit comments