1--TEST--
2socket_import_stream: effects of closing
3--EXTENSIONS--
4sockets
5--SKIPIF--
6<?php
7
8if(substr(PHP_OS, 0, 3) == 'WIN' ) {
9  die("skip Not Valid for Windows");
10}
11--FILE--
12<?php
13
14function test($stream, $sock) {
15    if ($stream !== null) {
16        echo "stream_set_blocking ";
17        try {
18            print_r(stream_set_blocking($stream, 0));
19        } catch (Error $e) {
20            echo get_class($e), ": ", $e->getMessage(), "\n";
21        }
22        echo "\n";
23    }
24    if ($sock !== null) {
25        echo "socket_set_block ";
26        try {
27            print_r(socket_set_block($sock));
28        } catch (Error $e) {
29            echo get_class($e), ": ", $e->getMessage(), "\n";
30        }
31        echo "\n";
32        echo "socket_get_option ";
33        try {
34            print_r(socket_get_option($sock, SOL_SOCKET, SO_TYPE));
35        } catch (Error $e) {
36            echo get_class($e), ": ", $e->getMessage(), "\n";
37        }
38        echo "\n";
39    }
40    echo "\n";
41}
42
43echo "normal\n";
44$stream0 = stream_socket_server("udp://0.0.0.0:0", $errno, $errstr, STREAM_SERVER_BIND);
45$sock0 = socket_import_stream($stream0);
46test($stream0, $sock0);
47
48echo "\nunset stream\n";
49$stream1 = stream_socket_server("udp://0.0.0.0:0", $errno, $errstr, STREAM_SERVER_BIND);
50$sock1 = socket_import_stream($stream1);
51unset($stream1);
52test(null, $sock1);
53
54echo "\nunset socket\n";
55$stream2 = stream_socket_server("udp://0.0.0.0:0", $errno, $errstr, STREAM_SERVER_BIND);
56$sock2 = socket_import_stream($stream2);
57unset($sock2);
58test($stream2, null);
59
60echo "\nclose stream\n";
61$stream3 = stream_socket_server("udp://0.0.0.0:0", $errno, $errstr, STREAM_SERVER_BIND);
62$sock3 = socket_import_stream($stream3);
63fclose($stream3);
64test($stream3, $sock3);
65
66echo "\nclose socket\n";
67$stream4 = stream_socket_server("udp://0.0.0.0:0", $errno, $errstr, STREAM_SERVER_BIND);
68$sock4 = socket_import_stream($stream4);
69socket_close($sock4);
70test($stream4, $sock4);
71
72echo "Done.\n";
73?>
74--EXPECTF--
75normal
76stream_set_blocking 1
77socket_set_block 1
78socket_get_option 2
79
80
81unset stream
82socket_set_block 1
83socket_get_option 2
84
85
86unset socket
87stream_set_blocking 1
88
89
90close stream
91stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
92
93socket_set_block
94Warning: socket_set_block(): unable to set blocking mode [%d]: %s in %s on line %d
95
96socket_get_option
97Warning: socket_get_option(): Unable to retrieve socket option [%d]: %s in %s on line %d
98
99
100
101close socket
102stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
103
104socket_set_block Error: socket_set_block(): Argument #1 ($socket) has already been closed
105
106socket_get_option Error: socket_get_option(): Argument #1 ($socket) has already been closed
107
108
109Done.
110