Skip to content

Commit

Permalink
Allow string ports for resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
danijar committed Sep 15, 2024
1 parent f8e0cab commit 7245fe0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion portal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '3.2.2'
__version__ = '3.2.3'

import multiprocessing as mp
try:
Expand Down
19 changes: 10 additions & 9 deletions portal/client_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 7245fe0

Please sign in to comment.