diff --git a/src/lib/libcore.js b/src/lib/libcore.js index d774ed139d044..f5f5f510e9d5f 100644 --- a/src/lib/libcore.js +++ b/src/lib/libcore.js @@ -2617,7 +2617,11 @@ function wrapSyscallFunction(x, library, isWasi) { post = handler + post; if (pre || post) { - t = modifyJSFunction(t, (args, body) => `function (${args}) {\n${pre}${body}${post}}\n`); + if (library[x + '__async']) { + t = modifyJSFunction(t, (args, body) => `async function (${args}) {\n${pre}${body}${post}}\n`); + } else { + t = modifyJSFunction(t, (args, body) => `function (${args}) {\n${pre}${body}${post}}\n`); + } } library[x] = eval('(' + t + ')'); diff --git a/src/lib/libsockfs.js b/src/lib/libsockfs.js index 493d2e749341f..984b4d6cd7d3c 100644 --- a/src/lib/libsockfs.js +++ b/src/lib/libsockfs.js @@ -104,9 +104,9 @@ addToLibrary({ }, // node and stream ops are backend agnostic stream_ops: { - poll(stream) { + poll(stream, timeout) { var sock = stream.node.sock; - return sock.sock_ops.poll(sock); + return sock.sock_ops.poll(sock, timeout); }, ioctl(stream, request, varargs) { var sock = stream.node.sock; @@ -375,7 +375,7 @@ addToLibrary({ // // actual sock ops // - poll(sock) { + poll(sock, timeout) { if (sock.type === {{{ cDefs.SOCK_STREAM }}} && sock.server) { // listen sockets should only say they're available for reading // if there are pending clients. diff --git a/src/lib/libsyscall.js b/src/lib/libsyscall.js index 773d4c76300fe..5c804d98ce986 100644 --- a/src/lib/libsyscall.js +++ b/src/lib/libsyscall.js @@ -543,7 +543,13 @@ var SyscallsLibrary = { return 0; }, __syscall__newselect__i53abi: true, - __syscall__newselect: (nfds, readfds, writefds, exceptfds, timeoutInMillis) => { +#if ASYNCIFY + __syscall__newselect__async: true, + __syscall__newselect: async (nfds, readfds, writefds, exceptfds, timeoutInMillis) => +#else + __syscall__newselect: (nfds, readfds, writefds, exceptfds, timeoutInMillis) => +#endif + { // readfds are supported, // writefds checks socket open status // exceptfds are supported, although on web, such exceptional conditions never arise in web sockets @@ -586,6 +592,11 @@ var SyscallsLibrary = { if (stream.stream_ops.poll) { flags = stream.stream_ops.poll(stream, timeoutInMillis); + +#if ASYNCIFY + /* poll is possibly a promise */ + flags = await flags; +#endif } else { #if ASSERTIONS if (timeoutInMillis != 0) warnOnce('non-zero select() timeout not supported: ' + timeoutInMillis)