Skip to content

Commit 860c75c

Browse files
committed
php#53: Fix async stream event optimization for composite read events
The optimization for reusing cached async events was not working for PHP_POLLREADABLE because it gets converted to composite flags (ASYNC_READABLE | ASYNC_DISCONNECT = 5) instead of pure ASYNC_READABLE (1). Changes: - Add READ_EVENT_MASK to define events covered by read_event cache - Change exact equality checks to subset matching for read events - Keep write_event logic unchanged (exact ASYNC_WRITABLE matching) This allows read_event to be reused for any combination of readable events (ASYNC_READABLE, ASYNC_DISCONNECT, or both), avoiding unnecessary proxy creation for common polling scenarios.
1 parent aa984e7 commit 860c75c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

main/streams/xp_socket.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,10 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
601601
}
602602
}
603603

604-
if (value == ASYNC_READABLE && sock->read_event) {
604+
// Mask of events covered by read_event (PHP_POLLREADABLE)
605+
#define READ_EVENT_MASK (ASYNC_READABLE | ASYNC_DISCONNECT)
606+
607+
if (sock->read_event && (value & READ_EVENT_MASK) == value) {
605608
*handle_ptr = (zend_async_poll_event_t*)sock->read_event;
606609
return PHP_STREAM_OPTION_RETURN_OK;
607610
}
@@ -619,8 +622,8 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
619622

620623
*handle_ptr = (zend_async_poll_event_t*)proxy;
621624

622-
// Cache standard event-proxy for reuse
623-
if (value == ASYNC_READABLE) {
625+
// Cache event-proxy for reuse
626+
if ((value & READ_EVENT_MASK) == value) {
624627
sock->read_event = proxy;
625628
} else if (value == ASYNC_WRITABLE) {
626629
sock->write_event = proxy;

0 commit comments

Comments
 (0)