Commit e15dc9ea authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #1256 from gevent/issue1252

Don't pass the port when calling getaddrinfo from socket.connect.
parents 7420a0da f5c8eeef
......@@ -16,6 +16,14 @@
:class:`concurrent.futures.ThreadPoolExecutor` as well. Reported in
:issue:`1248` by wwqgtxx and :issue:`1251` by pyld.
- :meth:`gevent.socket.socket.connect` doesn't pass the port (service)
to :func:`socket.getaddrinfo` when it resolves an ``AF_INET`` or
``AF_INET6`` address. This fixes an issue on Solaris. Reported in
:issue:`1252` by wiggin15.
- :meth:`gevent.socket.socket.connect` works with more address
families, notably AF_TIPC, AF_NETLINK, AF_BLUETOOTH, AF_ALG and AF_VSOCK.
1.3.4 (2018-06-20)
==================
......
......@@ -228,9 +228,7 @@ class socket(object):
if self.timeout == 0.0:
return self._sock.connect(address)
sock = self._sock
if isinstance(address, tuple):
r = getaddrinfo(address[0], address[1], sock.family)
address = r[0][-1]
address = _socketcommon._resolve_addr(sock, address)
timer = Timeout._start_new_or_dummy(self.timeout, timeout('timed out'))
try:
......
......@@ -326,9 +326,7 @@ class socket(object):
def connect(self, address):
if self.timeout == 0.0:
return _socket.socket.connect(self._sock, address)
if isinstance(address, tuple):
r = getaddrinfo(address[0], address[1], self.family)
address = r[0][-1]
address = _socketcommon._resolve_addr(self._sock, address)
with Timeout._start_new_or_dummy(self.timeout, timeout("timed out")):
while True:
......
......@@ -354,3 +354,29 @@ def _sendall(socket, data_memory, flags,
timeleft = __send_chunk(socket, chunk, flags, timeleft, end)
data_sent += len(chunk) # Guaranteed it sent the whole thing
# pylint:disable=no-member
_RESOLVABLE_FAMILIES = (__socket__.AF_INET,)
if __socket__.has_ipv6:
_RESOLVABLE_FAMILIES += (__socket__.AF_INET6,)
def _resolve_addr(sock, address):
# Internal method: resolve the AF_INET[6] address using
# getaddrinfo.
if sock.family not in _RESOLVABLE_FAMILIES or not isinstance(address, tuple):
return address
# address is (host, port) (ipv4) or (host, port, flowinfo, scopeid) (ipv6).
# We don't pass the port to getaddrinfo because the C
# socket module doesn't either (on some systems its
# illegal to do that without also passing socket type and
# protocol). Instead we join the port back at the end.
# See https://github.com/gevent/gevent/issues/1252
host, port = address[:2]
r = getaddrinfo(host, None, sock.family)
address = r[0][-1]
if len(address) == 2:
address = (address[0], port)
else:
address = (address[0], port, address[2], address[3])
return address
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment