You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Description
This PR adds supports for reading from non-blocking streams
(`stream_set_blocking($fp, true)`) by aligning the streaming logic with
unix kernel:
* `stream_set_blocking()` is now able to correctly mark the OS stream as
non blocking via `fcntl()`
* `fd_read()` either blocks or immediately returns based on stream type
* `js_open_process()`, `proc_open()` et al. now work directly with
kernel pipes. There's no more special event-based handling, polling, or
special casing for pumping stdin data to the process.
* PIPEFS no longer returns EWOULDBLOCK when the pipe is blocking, lacks
data, and the other side is already closed
* Removed special cases for polling processes, including
`PHPWASM.child_proc_by_fd`. We rely on kernel pipes now.
* Removed PHP 7.4 patch to treat blocking streams in a special way
### Motivation for this patch
With this PR, we can use the Symfony Process component. It spawns a new
process via proc_open(), marks its output stream as non-blocking, and
immediately reads the initial output bytes if any are present. Before
this change, Playground would block until the first output is produced,
and, sometimes until the entire process finishes.
This PR is a pre-requisite to #2281
### Other changes
This PR implements `usleep()` (via `-Wl,--wrap=usleep`). It turns out
that it wasn't actually blocking the execution and a few unit tests
relying on it only passed due to a buggy implementation of blocking
streams.
### Follow-up work
* Replace `read()` globally with something equivalent to `wasm_read()`.
Right now we only do this `RUN /root/replace.sh 's/ret = read/ret =
wasm_read/g' /root/php-src/main/streams/plain_wrapper.c`
* Consider not overriding `php_pollfd_for` and removing
`wasm_poll_socket()` – wrapping select/poll/read syscalls may be enough
* We could remove more special casing, including socket polling inside
`wasm_poll_socket`, the `js_popen_to_file` function, `awaitData` et al.
## Testing Instructions (or ideally a Blueprint)
Tests are included so just confirm the CI is green.
# PIPEFS: return 0 (success) instead of 6 (EWOULDBLOCK) when reached end of data
2200
+
# and the other end of the pipe is closed.
2201
+
/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; \
2197
2202
# Add MSG_PEEK flag support in recvfrom
2198
2203
#
2199
2204
# Emscripten ignores the flags argument to ___syscall_recvfrom.
0 commit comments