diff --git a/portal/__init__.py b/portal/__init__.py index 0cce755..5820ef7 100644 --- a/portal/__init__.py +++ b/portal/__init__.py @@ -1,4 +1,4 @@ -__version__ = '3.2.2' +__version__ = '3.2.3' import multiprocessing as mp try: diff --git a/portal/client_socket.py b/portal/client_socket.py index 3f3ddf1..a7d8fd6 100644 --- a/portal/client_socket.py +++ b/portal/client_socket.py @@ -179,16 +179,19 @@ def _loop(self): sock.close() def _connect(self): - host, port = self.addr - self._log(f'Connecting to {host}:{port}') + self._log(f'Connecting to {self.addr[0]}:{self.addr[1]}') once = True while self.running: - sock, addr = self._create() + # We need to resolve the address regularly. + host, port = self.addr + if contextlib.context.resolver: + host, port = contextlib.context.resolver((host, port)) + assert isinstance(host, str), (host, port) + assert isinstance(port, int), (host, port) + addr = (host, port, 0, 0) if self.options.ipv6 else (host, port) + sock = self._create() error = None try: - # We need to resolve the address regularly. - if contextlib.context.resolver: - addr = contextlib.context.resolver(addr) sock.settimeout(10) sock.connect(addr) sock.settimeout(0) @@ -210,10 +213,8 @@ def _connect(self): def _create(self): if self.options.ipv6: sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) - addr = (*self.addr, 0, 0) else: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - addr = self.addr # sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) after = self.options.keepalive_after every = self.options.keepalive_every @@ -231,7 +232,7 @@ def _create(self): sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPALIVE, every) if sys.platform == 'win32': sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, after * 1000, every * 1000)) - return sock, addr + return sock def _log(self, *args): if not self.options.logging: