extmod/asyncio: Add IPv6 support to start_server().

Ensures that the underlying socket is opened with the correct protocol as
parsed by `getaddrinfo()`.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This commit is contained in:
Andrew Leech
2025-07-22 19:38:06 +10:00
committed by Damien George
parent 35d07df445
commit 2d14d4ef41

View File

@@ -180,11 +180,11 @@ async def start_server(cb, host, port, backlog=5, ssl=None):
import socket
# Create and bind server socket.
host = socket.getaddrinfo(host, port)[0] # TODO this is blocking!
s = socket.socket()
addr_info = socket.getaddrinfo(host, port)[0] # TODO this is blocking!
s = socket.socket(addr_info[0]) # Use address family from getaddrinfo
s.setblocking(False)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(host[-1])
s.bind(addr_info[-1])
s.listen(backlog)
# Create and return server object and task.