mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-06-28 03:41:41 +00:00
Fix listen_on with IPv6 address
This commit is contained in:
parent
fdc3c3d7c1
commit
d363513884
2 changed files with 11 additions and 5 deletions
|
|
@ -173,10 +173,9 @@ def listen_on(spec: str) -> tuple[int, str]:
|
|||
atexit.register(remove_socket_file, s, socket_path)
|
||||
s.bind(address)
|
||||
s.listen()
|
||||
if isinstance(address, tuple):
|
||||
h, resolved_port = s.getsockname()
|
||||
sfamily, host, port = spec.split(':', 2)
|
||||
spec = f'{sfamily}:{host}:{resolved_port}'
|
||||
if isinstance(address, tuple): # tcp socket
|
||||
h, resolved_port = s.getsockname()[:2]
|
||||
spec = spec.rpartition(':')[0] + f':{resolved_port}'
|
||||
return s.fileno(), spec
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -492,7 +492,14 @@ def parse_address_spec(spec: str) -> tuple[AddressFamily, Union[tuple[str, int],
|
|||
socket_path = address
|
||||
elif protocol in ('tcp', 'tcp6'):
|
||||
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)
|
||||
else:
|
||||
raise ValueError(f'Unknown protocol in listen-on value: {spec}')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue