Skip to content

Commit 425265c

Browse files
committed
poll: add wsapoll backend with additional tests and fix Win compat
1 parent fbeb78c commit 425265c

14 files changed

+458
-25
lines changed

ext/standard/stream_poll.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
const STREAM_POLL_BACKEND_EVENTPORT = UNKNOWN;
6666
/**
6767
* @var int
68-
* @cvalue PHP_POLL_BACKEND_IOCP
68+
* @cvalue PHP_POLL_BACKEND_WSAPOLL
6969
*/
70-
const STREAM_POLL_BACKEND_IOCP = UNKNOWN;
70+
const STREAM_POLL_BACKEND_WSAPOLL = UNKNOWN;
7171

7272
final class StreamPollContext
7373
{

ext/standard/stream_poll_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/tests/streams/stream_poll_backend_name_basic.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
--TEST--
22
Stream polling - backend name
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die ("skip not for Windows");
7+
}
8+
?>
39
--FILE--
410
<?php
511
require_once __DIR__ . '/stream_poll.inc';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Stream polling - backend name on Windows
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) != 'WIN') {
6+
die ("skip only for Windows");
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
require_once __DIR__ . '/stream_poll.inc';
12+
// select is always available
13+
$poll_ctx = stream_poll_create(STREAM_POLL_BACKEND_WSAPOLL);
14+
var_dump(stream_poll_backend_name($poll_ctx));
15+
// test with string
16+
$poll_ctx = stream_poll_create('wsapoll');
17+
var_dump(stream_poll_backend_name($poll_ctx));
18+
19+
?>
20+
--EXPECT--
21+
string(7) "wsapoll"
22+
string(7) "wsapoll"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Stream polling - socket write / read close
3+
--FILE--
4+
<?php
5+
require_once __DIR__ . '/stream_poll.inc';
6+
7+
list($socket1r, $socket1w) = pt_new_socket_pair();
8+
$poll_ctx = pt_new_stream_poll();
9+
10+
stream_poll_add($poll_ctx, $socket1r, STREAM_POLL_READ, "socket1_data");
11+
stream_poll_add($poll_ctx, $socket1w, STREAM_POLL_WRITE, "socket2_data");
12+
13+
fwrite($socket1w, "test data");
14+
15+
fclose($socket1r);
16+
pt_expect_events(stream_poll_wait($poll_ctx, 100), [
17+
[
18+
'events' => ['default' => STREAM_POLL_WRITE|STREAM_POLL_HUP, 'poll' => STREAM_POLL_HUP],
19+
'data' => 'socket2_data'
20+
]
21+
], $poll_ctx);
22+
23+
fclose($socket1w);
24+
pt_expect_events(stream_poll_wait($poll_ctx, 100), []);
25+
26+
?>
27+
--EXPECT--
28+
Events matched - count: 1
29+
Events matched - count: 0

ext/standard/tests/streams/stream_poll_basic_sock_rw_multi_edge.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Stream polling - socket write / read multiple times with edge triggering
33
--SKIPIF--
44
<?php
55
require_once __DIR__ . '/stream_poll.inc';
6-
pt_skip_for_backend(['poll', 'select'], 'does not support edge triggering')
6+
pt_skip_for_backend(['poll', 'wsapoll'], 'does not support edge triggering')
77
?>
88
--FILE--
99
<?php

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
@@ -3,7 +3,7 @@ Stream polling - socket write / read few time only
33
--SKIPIF--
44
<?php
55
require_once __DIR__ . '/stream_poll.inc';
6-
pt_skip_for_backend(['poll', 'select'], 'does not support edge triggering')
6+
pt_skip_for_backend(['poll', 'wsapoll'], 'does not support edge triggering')
77
?>
88
--FILE--
99
<?php
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Stream polling - socket write close
3+
--FILE--
4+
<?php
5+
require_once __DIR__ . '/stream_poll.inc';
6+
7+
list($socket1r, $socket1w) = pt_new_socket_pair();
8+
$poll_ctx = pt_new_stream_poll();
9+
list($socket2r, $socket2w) = pt_new_socket_pair();
10+
$poll_ctx = pt_new_stream_poll();
11+
12+
stream_poll_add($poll_ctx, $socket1w, STREAM_POLL_WRITE, "socket1w_data");
13+
stream_poll_add($poll_ctx, $socket2w, STREAM_POLL_WRITE, "socket2w_data");
14+
15+
fclose($socket1w);
16+
fclose($socket2w);
17+
pt_expect_events(stream_poll_wait($poll_ctx, 100), []);
18+
19+
?>
20+
--EXPECT--
21+
Events matched - count: 0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Stream polling - socket read
3+
--FILE--
4+
<?php
5+
require_once __DIR__ . '/stream_poll.inc';
6+
7+
list($socket1r, $socket1w) = pt_new_tcp_socket_pair();
8+
$poll_ctx = pt_new_stream_poll();
9+
10+
stream_poll_add($poll_ctx, $socket1r, STREAM_POLL_READ, "socket_data");
11+
12+
pt_write_sleep($socket1w, "test data");
13+
pt_expect_events(stream_poll_wait($poll_ctx, 100), [
14+
['events' => STREAM_POLL_READ, 'data' => 'socket_data', 'read' => 'test data']
15+
]);
16+
17+
?>
18+
--EXPECT--
19+
Events matched - count: 1

main/php_poll.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ typedef enum {
3535
PHP_POLL_BACKEND_EPOLL,
3636
PHP_POLL_BACKEND_KQUEUE,
3737
PHP_POLL_BACKEND_EVENTPORT,
38-
PHP_POLL_BACKEND_IOCP
38+
PHP_POLL_BACKEND_WSAPOLL
3939
} php_poll_backend_type;
4040

4141
/* Error codes */

0 commit comments

Comments
 (0)