Pymet fix reverse_tcp transport for IPv6 addresses

This commit is contained in:
Spencer McIntyre 2015-07-02 08:33:11 -04:00
parent dbe239bc75
commit 6ab7c314de
1 changed files with 6 additions and 11 deletions

View File

@ -574,12 +574,7 @@ class TcpTransport(Transport):
sock.close() sock.close()
def _activate(self): def _activate(self):
if self.url.startswith('tcp:'): address, port = self.url[6:].rsplit(':', 1)
family = socket.AF_INET
address, port = self.url[6:].split(':', 1)
else:
family = socket.AF_INET6
address, port = self.url[7:].split(':', 1)
port = int(port.rstrip('/')) port = int(port.rstrip('/'))
timeout = max(self.communication_timeout, 30) timeout = max(self.communication_timeout, 30)
if address in ('', '0.0.0.0', '::'): if address in ('', '0.0.0.0', '::'):
@ -596,7 +591,10 @@ class TcpTransport(Transport):
sock, _ = server_sock.accept() sock, _ = server_sock.accept()
server_sock.close() server_sock.close()
else: else:
sock = socket.socket(family, socket.SOCK_STREAM) if ':' in address:
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout) sock.settimeout(timeout)
sock.connect((address, port)) sock.connect((address, port))
sock.settimeout(None) sock.settimeout(None)
@ -637,10 +635,7 @@ class TcpTransport(Transport):
@classmethod @classmethod
def from_socket(cls, sock): def from_socket(cls, sock):
if sock.family == socket.AF_INET: url = 'tcp://'
url = 'tcp://'
else:
url = 'tcp6://'
address, port = sock.getsockname()[:2] address, port = sock.getsockname()[:2]
# this will need to be changed if the bind stager ever supports binding to a specific address # this will need to be changed if the bind stager ever supports binding to a specific address
if not address in ('', '0.0.0.0', '::'): if not address in ('', '0.0.0.0', '::'):