Skip to content

Commit d939aa1

Browse files
committed
poll: remove incorrect edge triggering simulation
1 parent 22dd6d1 commit d939aa1

File tree

7 files changed

+42
-61
lines changed

7 files changed

+42
-61
lines changed

ext/standard/tests/streams/stream_poll.inc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<?php
22
// stream Poll Testing helper
3+
4+
function pt_new_stream_poll(): StreamPollContext {
5+
$backend = getenv('STREAM_POLL_TEST_BACKEND');
6+
return stream_poll_create($backend === false ? STREAM_POLL_BACKEND_AUTO : $backend);
7+
}
8+
9+
function pt_skip_for_backend($backend, $msg): void {
10+
$backends_to_skip = is_array($backend) ? $backend : array($backend);
11+
$current_backend = stream_poll_backend_name(pt_new_stream_poll());
12+
if (in_array($current_backend, $backends_to_skip)) {
13+
die("skip backend $current_backend $msg\n");
14+
}
15+
}
16+
317
function pt_new_socket_pair(): array {
418
$domain = (strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? STREAM_PF_INET : STREAM_PF_UNIX);
519
$sockets = stream_socket_pair($domain, STREAM_SOCK_STREAM, 0);
@@ -65,11 +79,6 @@ function pt_new_tcp_socket_connections(int $num_conns): array {
6579
return [$clients, $server_conns];
6680
}
6781

68-
function pt_new_stream_poll(): StreamPollContext {
69-
$backend = getenv('STREAM_POLL_TEST_BACKEND');
70-
return stream_poll_create($backend === false ? STREAM_POLL_BACKEND_AUTO : $backend);
71-
}
72-
7382
function pt_write_sleep($stream, $data, $delay = 10000): int|false {
7483
$result = fwrite($stream, $data, $delay);
7584
usleep($delay);

ext/standard/tests/streams/stream_poll_basic_sock_rw_multi_edge.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
--TEST--
22
Stream polling - socket write / read multiple times with edge triggering
3+
--SKIPIF--
4+
<?php
5+
require_once __DIR__ . '/stream_poll.inc';
6+
pt_skip_for_backend(['poll', 'select'], 'does not support edger triggering')
7+
?>
38
--FILE--
49
<?php
510
require_once __DIR__ . '/stream_poll.inc';

ext/standard/tests/streams/stream_poll_basic_sock_rw_single_edge.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ pt_expect_events(stream_poll_wait($poll_ctx, 100), [
2121
?>
2222
--EXPECT--
2323
Events matched - count: 1
24-
Events matched - count: 2
24+
Events matched - count: 1

main/poll/php_poll_internal.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ php_socket_t php_poll_fd_table_get_max_fd(php_poll_fd_table *table);
119119
int php_poll_fd_table_collect_events(
120120
php_poll_fd_table *table, php_poll_event *events, int max_events);
121121

122-
/* Edge triggering simulation helper */
123-
int php_poll_simulate_edge_trigger(php_poll_fd_table *table, php_poll_event *events, int nfds);
124-
125122
/* Error helper functions */
126123
php_poll_error php_poll_errno_to_error(int err);
127124

main/poll/poll_backend_poll.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ static zend_result poll_backend_add(php_poll_ctx *ctx, int fd, uint32_t events,
109109
{
110110
poll_backend_data_t *backend_data = (poll_backend_data_t *) ctx->backend_data;
111111

112+
if (events & PHP_POLL_ET) {
113+
php_poll_set_error(ctx, PHP_POLL_ERR_NOSUPPORT);
114+
return FAILURE;
115+
}
116+
112117
if (php_poll_fd_table_find(backend_data->fd_table, fd)) {
113118
php_poll_set_error(ctx, PHP_POLL_ERR_EXISTS);
114119
return FAILURE;
@@ -130,6 +135,11 @@ static zend_result poll_backend_modify(php_poll_ctx *ctx, int fd, uint32_t event
130135
{
131136
poll_backend_data_t *backend_data = (poll_backend_data_t *) ctx->backend_data;
132137

138+
if (events & PHP_POLL_ET) {
139+
php_poll_set_error(ctx, PHP_POLL_ERR_NOSUPPORT);
140+
return FAILURE;
141+
}
142+
133143
php_poll_fd_entry *entry = php_poll_fd_table_find(backend_data->fd_table, fd);
134144
if (!entry) {
135145
php_poll_set_error(ctx, PHP_POLL_ERR_NOTFOUND);
@@ -256,9 +266,6 @@ static int poll_backend_wait(php_poll_ctx *ctx, php_poll_event *events, int max_
256266
backend_data->fd_table, poll_process_results_callback, &result_ctx);
257267
int event_count = result_ctx.event_count;
258268

259-
/* Apply edge-trigger simulation */
260-
nfds = php_poll_simulate_edge_trigger(backend_data->fd_table, events, event_count);
261-
262269
/* Handle oneshot removals */
263270
for (int i = 0; i < nfds; i++) {
264271
php_poll_fd_entry *entry = php_poll_fd_table_find(backend_data->fd_table, events[i].fd);

main/poll/poll_backend_select.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ static zend_result select_backend_add(php_poll_ctx *ctx, int fd, uint32_t events
9494
select_backend_data_t *backend_data = (select_backend_data_t *) ctx->backend_data;
9595
php_socket_t sock = (php_socket_t) fd;
9696

97+
if (events & PHP_POLL_ET) {
98+
php_poll_set_error(ctx, PHP_POLL_ERR_NOSUPPORT);
99+
return FAILURE;
100+
}
101+
97102
#ifdef FD_SETSIZE
98103
if (sock >= FD_SETSIZE) {
99104
php_poll_set_error(ctx, PHP_POLL_ERR_INVALID);
@@ -139,6 +144,11 @@ static zend_result select_backend_modify(
139144
select_backend_data_t *backend_data = (select_backend_data_t *) ctx->backend_data;
140145
php_socket_t sock = (php_socket_t) fd;
141146

147+
if (events & PHP_POLL_ET) {
148+
php_poll_set_error(ctx, PHP_POLL_ERR_NOSUPPORT);
149+
return FAILURE;
150+
}
151+
142152
php_poll_fd_entry *entry = php_poll_fd_table_find(backend_data->fd_table, fd);
143153
if (!entry) {
144154
php_poll_set_error(ctx, PHP_POLL_ERR_NOTFOUND);
@@ -293,18 +303,15 @@ static int select_backend_wait(
293303
php_poll_fd_table_foreach(backend_data->fd_table, process_select_result_callback, &result_ctx);
294304
int event_count = result_ctx.event_count;
295305

296-
/* Apply edge-trigger simulation */
297-
int nfds = php_poll_simulate_edge_trigger(backend_data->fd_table, events, event_count);
298-
299306
/* Handle oneshot removals */
300-
for (int i = 0; i < nfds; i++) {
307+
for (int i = 0; i < event_count; i++) {
301308
php_poll_fd_entry *entry = php_poll_fd_table_find(backend_data->fd_table, events[i].fd);
302309
if (entry && (entry->events & PHP_POLL_ONESHOT) && events[i].revents != 0) {
303310
select_handle_oneshot_removal(backend_data, events[i].fd);
304311
}
305312
}
306313

307-
return nfds;
314+
return event_count;
308315
}
309316

310317
static bool select_backend_is_available(void)

main/poll/poll_core.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -406,47 +406,3 @@ PHPAPI const char *php_poll_error_string(php_poll_error error)
406406
return "Unknown error";
407407
}
408408
}
409-
410-
/* Edge-trigger simulation helper */
411-
int php_poll_simulate_edge_trigger(php_poll_fd_table *table, php_poll_event *events, int nfds)
412-
{
413-
int filtered_count = 0;
414-
415-
for (int i = 0; i < nfds; i++) {
416-
php_poll_fd_entry *entry = php_poll_fd_table_find(table, events[i].fd);
417-
if (!entry) {
418-
continue;
419-
}
420-
421-
uint32_t new_events = events[i].revents;
422-
uint32_t reported_events = 0;
423-
424-
if (entry->events & PHP_POLL_ET) {
425-
/* Edge-triggered: report edges only */
426-
if ((new_events & PHP_POLL_READ) && !(entry->last_revents & PHP_POLL_READ)) {
427-
reported_events |= PHP_POLL_READ;
428-
}
429-
if ((new_events & PHP_POLL_WRITE) && !(entry->last_revents & PHP_POLL_WRITE)) {
430-
reported_events |= PHP_POLL_WRITE;
431-
}
432-
/* Always report error and hangup events */
433-
reported_events |= (new_events & (PHP_POLL_ERROR | PHP_POLL_HUP | PHP_POLL_RDHUP));
434-
} else {
435-
/* Level-triggered: report all active events */
436-
reported_events = new_events;
437-
}
438-
439-
entry->last_revents = new_events;
440-
441-
/* Only include this event if we have something to report */
442-
if (reported_events != 0) {
443-
if (filtered_count != i) {
444-
events[filtered_count] = events[i];
445-
}
446-
events[filtered_count].revents = reported_events;
447-
filtered_count++;
448-
}
449-
}
450-
451-
return filtered_count;
452-
}

0 commit comments

Comments
 (0)