xref: /php-src/ext/standard/tests/streams/gh8472.phpt (revision d9ff5e07)
1--TEST--
2GH-8472: The resource returned by stream_socket_accept may have incorrect metadata
3--FILE--
4<?php
5function setNonBlocking($stream)
6{
7    $block = stream_get_meta_data($stream)['blocked'];
8    if ($block) {
9        stream_set_blocking($stream, false);
10    }
11}
12
13$server = stream_socket_server("tcp://127.0.0.1:9100");
14setNonBlocking($server);
15
16$client = stream_socket_client("tcp://127.0.0.1:9100");
17
18$res = stream_socket_accept($server);
19stream_set_timeout($res, 1);
20setNonBlocking($res);
21
22fwrite($client, str_repeat('0', 5));
23
24$read = [$res];
25$write = [];
26$except = [];
27
28if (stream_select($read, $write, $except, 1)) {
29    var_dump(fread($res, 4));
30    var_dump(fread($res, 4));
31}
32?>
33--EXPECT--
34string(4) "0000"
35string(1) "0"
36