Skip to content

Simplify wasm_poll_socket #2355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 37 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9ad80ba
Support non-blocking read streams
adamziel Jul 5, 2025
ba2342e
Comment out O_DIRECT
adamziel Jul 5, 2025
108ddac
Comment out O_NOATIME
adamziel Jul 5, 2025
a510512
Comment out O_NOATIME
adamziel Jul 5, 2025
ecf1e4a
Redefine O_ macros
adamziel Jul 5, 2025
68525f6
Reformat
adamziel Jul 5, 2025
441efc4
Add a unit test for non-blocking proc_open fd
adamziel Jul 5, 2025
383db9e
Remove special casing for PHPWASM.child_proc_by_fd. Rely on streaming…
adamziel Jul 7, 2025
c5920b2
Non-blocking streams support without refactoring polling
adamziel Jul 8, 2025
212623b
Rebuild Asyncify PHP for Node.js
adamziel Jul 8, 2025
afa7fdf
Rebuild JSPI PHP for Node.js
adamziel Jul 8, 2025
ae16805
Rebuild PHP for the web
adamziel Jul 8, 2025
4339f3b
lint
adamziel Jul 8, 2025
8187077
Merge branch 'trunk' into partial-nonblocking-streams-support
adamziel Jul 8, 2025
35d6272
Harmonizing the ProcessAPI implementation with the new pipes contract
adamziel Jul 9, 2025
84011b0
adamziel Jul 9, 2025
056ce51
Get proc_open() tests to work
adamziel Jul 9, 2025
ef923fd
Inspect proc_open() tests and get them to work
adamziel Jul 9, 2025
eb43b67
Rebuild PHP 7.4 with updated process pipes
adamziel Jul 9, 2025
5b434e8
Clean up phpwasm-emscripten-library.js, remove parts we don't need an…
adamziel Jul 9, 2025
24b49df
Pump() the data periodically in js_open_process
adamziel Jul 9, 2025
1bdf692
Simplify Stdin handling – remove stream_ops overrides
adamziel Jul 9, 2025
c7a218f
Final cleanup
adamziel Jul 9, 2025
f01a360
Rebuild a few PHP versions
adamziel Jul 9, 2025
c86e174
Merge branch 'trunk' into partial-nonblocking-streams-support
adamziel Jul 9, 2025
7e81cd9
Lint, more PHP versions rebuilt
adamziel Jul 9, 2025
b4f5fcd
Lint, more PHP versions rebuilt
adamziel Jul 9, 2025
7ad008c
Lint, more PHP versions rebuilt
adamziel Jul 9, 2025
0d11a91
Lint, more PHP versions rebuilt
adamziel Jul 10, 2025
04a2dff
Rebuild PHP 7.4
adamziel Jul 10, 2025
59970a3
Instrument jspi builds
adamziel Jul 11, 2025
dfc381d
Rebuild Node.js PHP JSPI
adamziel Jul 12, 2025
349fa52
Rebuild web PHP
adamziel Jul 12, 2025
aec292b
Await php_wasm_init
adamziel Jul 13, 2025
98d5ff9
Remove JSPI-specific workaround
adamziel Jul 13, 2025
b09c25e
Simplify wasm_poll_socket
adamziel Jul 13, 2025
52bda71
Simplify socket handling – polling, setsockopt
adamziel Jul 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
"cli",\
"close_stmt_and_copy_errors",\
"close",\
"__stdio_close",\
"closeUnixFile",\
"compile_file",\
"createCollation",\
Expand Down Expand Up @@ -2060,7 +2061,7 @@ RUN set -euxo pipefail; \
source /root/emsdk/emsdk_env.sh; \
if [ "$WITH_JSPI" = "yes" ]; then \
# Both imports and exports are required for inter-module communication with wrapped methods, e.g., wasm_recv.
export ASYNCIFY_FLAGS=" -s ASYNCIFY=2 -sSUPPORT_LONGJMP=wasm -fwasm-exceptions -sJSPI_IMPORTS=js_open_process,js_waitpid,js_process_status,js_create_input_device,wasm_setsockopt,wasm_shutdown,wasm_close,wasm_recv -sJSPI_EXPORTS=wasm_sleep,wasm_read,emscripten_sleep,wasm_sapi_handle_request,wasm_sapi_request_shutdown,wasm_poll_socket,wrap_select,__wrap_select,select,php_pollfd_for,fflush,wasm_popen,wasm_read,wasm_php_exec,run_cli,wasm_recv -s EXTRA_EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports,_malloc "; \
export ASYNCIFY_FLAGS=" -s ASYNCIFY=2 -sSUPPORT_LONGJMP=wasm -fwasm-exceptions -sJSPI_IMPORTS=js_open_process,js_fd_read,js_waitpid,js_process_status,js_create_input_device,wasm_setsockopt,wasm_shutdown,wasm_close,wasm_recv,__syscall_fcntl64,js_flock,js_release_file_locks,js_waitpid,fd_close -sJSPI_EXPORTS=php_wasm_init,fd_close,wasm_sleep,wasm_read,emscripten_sleep,wasm_sapi_handle_request,wasm_sapi_request_shutdown,wasm_poll_socket,wrap_select,__wrap_select,select,php_pollfd_for,fflush,wasm_popen,wasm_read,wasm_php_exec,run_cli,wasm_recv -s EXTRA_EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports,_malloc "; \
echo '#define PLAYGROUND_JSPI 1' > /root/php_wasm_asyncify.h; \
else \
export ASYNCIFY_FLAGS=" -s ASYNCIFY=1 -s ASYNCIFY_IGNORE_INDIRECT=1 -s EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports $(cat /root/.emcc-php-asyncify-flags) "; \
Expand Down Expand Up @@ -2134,6 +2135,7 @@ RUN set -euxo pipefail; \
-o /build/output/php.js \
-s EXIT_RUNTIME=1 \
-Wl,--wrap=select \
-Wl,--wrap=usleep \
/root/lib/libphp.a \
/root/proc_open.c \
/root/php_wasm.c \
Expand Down Expand Up @@ -2194,6 +2196,9 @@ RUN set -euxo pipefail; \
/root/replace.sh "s/sock\.server\s*=\s*new WebSocketServer/if (Module['websocket']['serverDecorator']) {WebSocketServer = Module['websocket']['serverDecorator'](WebSocketServer);}sock.server = new WebSocketServer/g" /root/output/php.js; \
fi; \
fi; \
# PIPEFS: return 0 (success) instead of 6 (EWOULDBLOCK) when reached end of data
# and the other end of the pipe is closed.
/root/replace-across-lines.sh 's/if\s*\(\s*currentLength\s*==\s*0\s*\)\s*\{.{0,200}throw new FS.ErrnoError\(\s*6\s*\)/if(currentLength==0){if(pipe.refcnt<2){return 0;}throw new FS.ErrnoError(6)/sg' /root/output/php.js; \
# Add MSG_PEEK flag support in recvfrom
#
# Emscripten ignores the flags argument to ___syscall_recvfrom.
Expand Down
22 changes: 0 additions & 22 deletions packages/php-wasm/compile/php/php7.4.patch
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
diff --git a/php-src/main/streams/plain_wrapper.c b/php-src/main/streams/plain_wrapper.c
index 4d10e688b5..ca50261b8a 100644
--- a/php-src/main/streams/plain_wrapper.c
+++ b/php-src/main/streams/plain_wrapper.c
@@ -408,6 +408,15 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
}
#endif
ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
+ if(
+ (errno == EAGAIN || errno == EWOULDBLOCK) &&
+ (stream->flags & O_NONBLOCK) == 0
+ ) {
+ /* This is a blocking read in C but not in Emscripten.
+ Let's poll for data and try once again */
+ php_pollfd_for(data->fd, POLLIN, NULL);
+ ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
+ }

if (ret == (size_t)-1 && errno == EINTR) {
/* Read was interrupted, retry once,


diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
--- a/php-src/ext/standard/file.c
+++ b/php-src/ext/standard/file.c
Expand Down
Loading