Skip to content

Commit 2d53464

Browse files
committed
poll: add test and fix kqueue raw events
1 parent 69b29c8 commit 2d53464

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

ext/standard/stream_poll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ PHP_FUNCTION(stream_poll_create)
102102
bool raw_events = false;
103103
php_poll_ctx *poll_ctx;
104104

105-
ZEND_PARSE_PARAMETERS_START(0, 1)
105+
ZEND_PARSE_PARAMETERS_START(0, 2)
106106
Z_PARAM_OPTIONAL
107107
Z_PARAM_STR_OR_LONG(backend_str, backend_long)
108108
Z_PARAM_BOOL(raw_events)

ext/standard/tests/streams/stream_poll.inc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
// stream Poll Testing helper
33

4-
function pt_new_stream_poll(): StreamPollContext {
4+
function pt_new_stream_poll($raw_event = false): StreamPollContext {
55
$backend = getenv('STREAM_POLL_TEST_BACKEND');
6-
return stream_poll_create($backend === false ? STREAM_POLL_BACKEND_AUTO : $backend);
6+
return stream_poll_create($backend === false ? STREAM_POLL_BACKEND_AUTO : $backend, $raw_event);
77
}
88

99
function pt_skip_for_backend($backend, $msg): void {
@@ -14,6 +14,14 @@ function pt_skip_for_backend($backend, $msg): void {
1414
}
1515
}
1616

17+
function pt_skip_for_all_backends_except($backend, $msg): void {
18+
$backends_to_not_skip = is_array($backend) ? $backend : array($backend);
19+
$current_backend = stream_poll_backend_name(pt_new_stream_poll());
20+
if (!in_array($current_backend,$backends_to_not_skip)) {
21+
die("skip backend other than $current_backend $msg\n");
22+
}
23+
}
24+
1725
function pt_new_socket_pair(): array {
1826
$domain = (strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? STREAM_PF_INET : STREAM_PF_UNIX);
1927
$sockets = stream_socket_pair($domain, STREAM_SOCK_STREAM, 0);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Stream polling - TCP read write level combined for kqueue raw events
3+
--SKIPIF--
4+
<?php
5+
require_once __DIR__ . '/stream_poll.inc';
6+
pt_skip_for_all_backends_except('kqueue', 'are different for raw event')
7+
?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . '/stream_poll.inc';
11+
12+
list($client, $server) = pt_new_tcp_socket_pair();
13+
$poll_ctx = pt_new_stream_poll(true);
14+
15+
stream_poll_add($poll_ctx, $client, STREAM_POLL_READ | STREAM_POLL_WRITE, "client_data");
16+
stream_poll_add($poll_ctx, $server, STREAM_POLL_READ | STREAM_POLL_WRITE, "server_data");
17+
18+
pt_expect_events(stream_poll_wait($poll_ctx, 0), [
19+
['events' => STREAM_POLL_WRITE, 'data' => 'client_data'],
20+
['events' => STREAM_POLL_WRITE, 'data' => 'server_data']
21+
]);
22+
23+
fwrite($client, "test data");
24+
usleep(10000);
25+
pt_expect_events(stream_poll_wait($poll_ctx, 100), [
26+
['events' => STREAM_POLL_WRITE, 'data' => 'client_data'],
27+
['events' => STREAM_POLL_WRITE, 'data' => 'server_data'],
28+
['events' => STREAM_POLL_READ, 'data' => 'server_data', 'read' => 'test data']
29+
]);
30+
31+
?>
32+
--EXPECT--
33+
Events matched - count: 2
34+
Events matched - count: 3

main/poll/poll_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static php_poll_ctx *php_poll_create_context(uint32_t flags)
107107
return NULL;
108108
}
109109
ctx->persistent = persistent;
110-
ctx->raw_events = flags & PHP_POLL_FLAG_RAW_EVENTS;
110+
ctx->raw_events = (flags & PHP_POLL_FLAG_RAW_EVENTS) == PHP_POLL_FLAG_RAW_EVENTS;
111111

112112
return ctx;
113113
}

0 commit comments

Comments
 (0)