Skip to content

Commit

Permalink
asyncio (web)socket support
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Feb 3, 2023
1 parent ac9fab9 commit c6801c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
19 changes: 10 additions & 9 deletions support/__EMSCRIPTEN__.patches/3.11/asyncio/wasm_events.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Selector event loop for Em with signal handling."""
"""Selector event loop for emsdk."""
import sys

__EMSCRIPTEN__ = (sys.platform=='emscripten')


import errno
import os
import selectors
Expand Down Expand Up @@ -598,13 +597,15 @@ def sock_connect(self, sock, address):
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")

if not hasattr(socket, "AF_UNIX") or sock.family != socket.AF_UNIX:
resolved = base_events._ensure_resolved(
address, family=sock.family, proto=sock.proto, loop=self
)
if not resolved.done():
yield from resolved
_, _, _, _, address = resolved.result()[0]
# https://github.com/emscripten-core/emscripten/issues/7417
if not __EMSCRIPTEN__:
if not hasattr(socket, "AF_UNIX") or sock.family != socket.AF_UNIX:
resolved = base_events._ensure_resolved(
address, family=sock.family, proto=sock.proto, loop=self
)
if not resolved.done():
yield from resolved
_, _, _, _, address = resolved.result()[0]

fut = self.create_future()
self._sock_connect(fut, sock, address)
Expand Down
19 changes: 10 additions & 9 deletions support/__EMSCRIPTEN__.patches/3.12/asyncio/wasm_events.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Selector event loop for Em with signal handling."""
"""Selector event loop for emsdk."""
import sys

__EMSCRIPTEN__ = (sys.platform=='emscripten')


import errno
import os
import selectors
Expand Down Expand Up @@ -598,13 +597,15 @@ def sock_connect(self, sock, address):
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")

if not hasattr(socket, "AF_UNIX") or sock.family != socket.AF_UNIX:
resolved = base_events._ensure_resolved(
address, family=sock.family, proto=sock.proto, loop=self
)
if not resolved.done():
yield from resolved
_, _, _, _, address = resolved.result()[0]
# https://github.com/emscripten-core/emscripten/issues/7417
if not __EMSCRIPTEN__:
if not hasattr(socket, "AF_UNIX") or sock.family != socket.AF_UNIX:
resolved = base_events._ensure_resolved(
address, family=sock.family, proto=sock.proto, loop=self
)
if not resolved.done():
yield from resolved
_, _, _, _, address = resolved.result()[0]

fut = self.create_future()
self._sock_connect(fut, sock, address)
Expand Down

0 comments on commit c6801c4

Please sign in to comment.