Skip to content

Commit f33de87

Browse files
committed
extmod/asyncio/stream.py: Add ipv6 support to start_server().
Detects if an ipv6 address has been passed in for host and opens an IPV6 socket instead. Signed-off-by: Andrew Leech <[email protected]>
1 parent f498a16 commit f33de87

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

extmod/asyncio/stream.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ async def start_server(cb, host, port, backlog=5, ssl=None):
180180
import socket
181181

182182
# Create and bind server socket.
183-
host = socket.getaddrinfo(host, port)[0] # TODO this is blocking!
184-
s = socket.socket()
183+
host = socket.getaddrinfo(host, port)[0][-1] # TODO this is blocking!
184+
proto = socket.AF_INET6 if ":" in host[0] else socket.AF_INET
185+
s = socket.socket(proto)
185186
s.setblocking(False)
186187
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
187-
s.bind(host[-1])
188+
s.bind(host)
188189
s.listen(backlog)
189190

190191
# Create and return server object and task.

0 commit comments

Comments
 (0)