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 Linux");
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?>
72--EXPECTF--
73normal
74stream_set_blocking 1
75socket_set_block 1
76socket_get_option 2
77
78
79unset stream
80socket_set_block 1
81socket_get_option 2
82
83
84unset socket
85stream_set_blocking 1
86
87
88close stream
89stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
90
91socket_set_block
92Warning: socket_set_block(): unable to set blocking mode [10038]: %s in %ssocket_import_stream-4-win.php on line %d
93
94socket_get_option
95Warning: socket_get_option(): Unable to retrieve socket option [10038]: %s in %ssocket_import_stream-4-win.php on line %d
96
97
98
99close socket
100stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
101
102socket_set_block Error: socket_set_block(): Argument #1 ($socket) has already been closed
103
104socket_get_option Error: socket_get_option(): Argument #1 ($socket) has already been closed
105