Skip to content

Commit 86f0bc4

Browse files
committed
http/client: Track number of records separately
1 parent 42d5f7e commit 86f0bc4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

http/client.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,13 @@ local function connect(options, timeout)
173173

174174
local host = options.host
175175
local records
176+
local n_records
176177
if path then
177178
records = { { family = family, path = path } }
179+
n_records = 1
178180
elseif http_util.is_ip(host) then
179181
records = { { family = family, host = host } }
182+
n_records = 1
180183
else
181184
local dns_resolver = options.dns_resolver or cqueues_dns.getpool()
182185
records = {}
@@ -188,6 +191,7 @@ local function connect(options, timeout)
188191
elseif family == cs.AF_INET6 then
189192
dns_lookup(records, dns_resolver, host, cqueues_dns_record.AAAA, cqueues_dns_record.AAAA, timeout)
190193
end
194+
n_records = #records
191195
timeout = deadline and deadline-monotime()
192196
end
193197

@@ -204,8 +208,7 @@ local function connect(options, timeout)
204208

205209
local lasterr, lasterrno = "The name does not resolve for the supplied parameters"
206210
local i = 1
207-
local n = #records
208-
while i <= n do
211+
while i <= n_records do
209212
local rec = records[i]
210213
connect_params.family = rec.family;
211214
connect_params.host = rec.host;
@@ -232,14 +235,14 @@ local function connect(options, timeout)
232235
-- If an address family is not supported then entirely remove that
233236
-- family from candidate records
234237
local af = connect_params.family
235-
for j=n, i+1, -1 do
238+
for j=n_records, i+1, -1 do
236239
if records[j].family == af then
237240
table.remove(records, j)
238-
n = n - 1
241+
n_records = n_records - 1
239242
end
240243
end
241244
table.remove(records, i)
242-
n = n - 1
245+
n_records = n_records - 1
243246
else
244247
i = i + 1
245248
end

0 commit comments

Comments
 (0)