@@ -122,6 +122,11 @@ local function dns_lookup(dns_resolver, host, query_type, filter_type, records,
122
122
end
123
123
124
124
local function connect (options , timeout )
125
+ local family = options .family
126
+ if family == nil then
127
+ family = cs .AF_UNSPEC
128
+ end
129
+
125
130
local bind = options .bind
126
131
if bind ~= nil then
127
132
assert (type (bind ) == " string" )
@@ -133,22 +138,32 @@ local function connect(options, timeout)
133
138
end
134
139
local ipv6 = bind_address :match (" ^%[([:%x]+)%]$" )
135
140
if ipv6 then
141
+ if family == cs .AF_UNSPEC then
142
+ family = cs .AF_INET6
143
+ elseif family ~= cs .AF_INET6 then
144
+ error (" cannot bind local IPv6 address when using other address family" )
145
+ end
136
146
bind_address = ipv6
147
+ else
148
+ if family == cs .AF_UNSPEC then
149
+ family = cs .AF_INET
150
+ elseif family ~= cs .AF_INET then
151
+ error (" cannot bind local IPv4 address when using other address family" )
152
+ end
137
153
end
138
154
bind = {
139
155
address = bind_address ;
140
156
port = bind_port ;
141
157
}
142
158
end
143
159
144
- local family = options .family
145
160
local path = options .path
146
161
local host = options .host
147
162
if not path and not http_util .is_ip (host ) then
148
163
local dns_resolver = options .dns_resolver or cqueues_dns .getpool ()
149
164
local deadline = timeout and monotime ()+ timeout
150
165
local records = {}
151
- if family == nil or family == cs .AF_UNSPEC then
166
+ if family == cs .AF_UNSPEC then
152
167
dns_lookup (dns_resolver , host , cqueues_dns_record .AAAA , nil , records , timeout )
153
168
dns_lookup (dns_resolver , host , cqueues_dns_record .A , nil , records , deadline and deadline - monotime ())
154
169
elseif family == cs .AF_INET then
0 commit comments