Repository navigation
Conversation
bukka
marked this pull request as ready for review
September 30, 2026 13:33
A stream can hold unread data in its buffer while its descriptor is idle. stream_select() treats such a stream as readable but a level watcher looked at the descriptor only, so a loop waiting for readability never woke up (phpGH-23948). Context::wait() now checks level watchers with Read interest for buffered data first and reports them with Read triggered. The backend is then asked without waiting so descriptor events are merged in and a watcher readable both ways is returned once. Edge watchers are not affected. A one-shot reported from its buffer is disarmed like one fired by the backend and modifyEvents() re-arms it. The check reads the stream buffer positions only and does no IO. The check is a handle operation so other handle types can provide it. It is registered separately as php_poll_handle_ext_ops because the handle ops struct cannot grow without an ABI change. This is temporary and the operation moves to the ops struct in master.
bukka
force-pushed
the
poll_buffered_data
branch
from
September 30, 2026 13:40
b1f5cab to
a96a61f
Compare
arnaud-lb
reviewed
Oct 9, 2026
| /* Extra handle ops registered per ops pointer (temporary, ABI) */ | ||
| typedef struct php_poll_handle_ext_ops { | ||
| /* Data above the descriptor that a read returns without waiting */ | ||
| bool (*has_buffered_data)(php_poll_handle_object *handle); |
Member
There was a problem hiding this comment.
It would make sense to add this operation on php_poll_handle_ops directly. We can make it optional (function can be null).
This pattern is adding complexity but the benefits are not obvious to me. This doesn't appear to be for decoupling or separation of concerns purposes. It saves one pointer per php_poll_handle_ops (or more if we add other extra ops), but we lose that in php_poll_handle_ext_ops_registry, plus the lookup.
Comment on lines
+991
to
+994
| if (watcher->wait_gen == gen) { | ||
| /* Already reported from its buffer */ | ||
| watcher->triggered_events |= events[i].revents; | ||
| continue; |
Member
There was a problem hiding this comment.
The watcher may end up being incorrectly skipped in case the gen overflows.
Does watcher->wait_gen need to survive? If not this could be a boolean if we reset it after this loop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A stream can hold unread data in its buffer while its descriptor is idle. stream_select() treats such a stream as readable but a level watcher looked at the descriptor only, so a loop waiting for readability never woke up (GH-23948).
Context::wait() now checks level watchers with Read interest for buffered data first and reports them with Read triggered. The backend is then asked without waiting so descriptor events are merged in and a watcher readable both ways is returned once. Edge watchers are not affected. A one-shot reported from its buffer is disarmed like one fired by the backend and modifyEvents() re-arms it. The check reads the stream buffer positions only and does no IO.
The check is a handle operation so other handle types can provide it. It is registered separately as php_poll_handle_ext_ops because the handle ops struct cannot grow without an ABI change. This is temporary and the operation moves to the ops struct in master.