mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-23 08:47:47 +02:00
Fix listen_on with IPv6 address
This commit is contained in:
@@ -173,10 +173,9 @@ def listen_on(spec: str) -> tuple[int, str]:
|
|||||||
atexit.register(remove_socket_file, s, socket_path)
|
atexit.register(remove_socket_file, s, socket_path)
|
||||||
s.bind(address)
|
s.bind(address)
|
||||||
s.listen()
|
s.listen()
|
||||||
if isinstance(address, tuple):
|
if isinstance(address, tuple): # tcp socket
|
||||||
h, resolved_port = s.getsockname()
|
h, resolved_port = s.getsockname()[:2]
|
||||||
sfamily, host, port = spec.split(':', 2)
|
spec = spec.rpartition(':')[0] + f':{resolved_port}'
|
||||||
spec = f'{sfamily}:{host}:{resolved_port}'
|
|
||||||
return s.fileno(), spec
|
return s.fileno(), spec
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -492,7 +492,14 @@ def parse_address_spec(spec: str) -> tuple[AddressFamily, Union[tuple[str, int],
|
|||||||
socket_path = address
|
socket_path = address
|
||||||
elif protocol in ('tcp', 'tcp6'):
|
elif protocol in ('tcp', 'tcp6'):
|
||||||
family = socket.AF_INET if protocol == 'tcp' else socket.AF_INET6
|
family = socket.AF_INET if protocol == 'tcp' else socket.AF_INET6
|
||||||
host, port = rest.rsplit(':', 1)
|
if rest.startswith('['): # ]
|
||||||
|
host = rest[1:]
|
||||||
|
host, sep, leftover = host.rpartition(']')
|
||||||
|
_, port = leftover.rsplit(':', 1)
|
||||||
|
if ':' in host and protocol == 'tcp':
|
||||||
|
family = socket.AF_INET6
|
||||||
|
else:
|
||||||
|
host, port = rest.rsplit(':', 1)
|
||||||
address = host, int(port)
|
address = host, int(port)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Unknown protocol in listen-on value: {spec}')
|
raise ValueError(f'Unknown protocol in listen-on value: {spec}')
|
||||||
|
|||||||
Reference in New Issue
Block a user