1--TEST--
2socket_import_stream: effects of closing
3--SKIPIF--
4<?php
5if (!extension_loaded('sockets')) {
6	die('SKIP sockets extension not available.');
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		print_r(stream_set_blocking($stream, 0));
18		echo "\n";
19	}
20	if ($sock !== null) {
21		echo "socket_set_block ";
22		print_r(socket_set_block($sock));
23		echo "\n";
24		echo "socket_get_option ";
25		print_r(socket_get_option($sock, SOL_SOCKET, SO_TYPE));
26		echo "\n";
27	}
28	echo "\n";
29}
30
31echo "normal\n";
32$stream0 = stream_socket_server("udp://0.0.0.0:58380", $errno, $errstr, STREAM_SERVER_BIND);
33$sock0 = socket_import_stream($stream0);
34test($stream0, $sock0);
35
36echo "\nunset stream\n";
37$stream1 = stream_socket_server("udp://0.0.0.0:58381", $errno, $errstr, STREAM_SERVER_BIND);
38$sock1 = socket_import_stream($stream1);
39unset($stream1);
40test(null, $sock1);
41
42echo "\nunset socket\n";
43$stream2 = stream_socket_server("udp://0.0.0.0:58382", $errno, $errstr, STREAM_SERVER_BIND);
44$sock2 = socket_import_stream($stream2);
45unset($sock2);
46test($stream2, null);
47
48echo "\nclose stream\n";
49$stream3 = stream_socket_server("udp://0.0.0.0:58383", $errno, $errstr, STREAM_SERVER_BIND);
50$sock3 = socket_import_stream($stream3);
51fclose($stream3);
52test($stream3, $sock3);
53
54echo "\nclose socket\n";
55$stream4 = stream_socket_server("udp://0.0.0.0:58384", $errno, $errstr, STREAM_SERVER_BIND);
56$sock4 = socket_import_stream($stream4);
57socket_close($sock4);
58test($stream4, $sock4);
59
60echo "Done.\n";
61--EXPECTF--
62normal
63stream_set_blocking 1
64socket_set_block 1
65socket_get_option 2
66
67
68unset stream
69socket_set_block 1
70socket_get_option 2
71
72
73unset socket
74stream_set_blocking 1
75
76
77close stream
78stream_set_blocking
79Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d
80
81socket_set_block
82Warning: socket_set_block(): unable to set blocking mode [10038]: %s
83 in %ssocket_import_stream-4-win.php on line %d
84
85socket_get_option
86Warning: socket_get_option(): unable to retrieve socket option [10038]: %s
87 in %ssocket_import_stream-4-win.php on line %d
88
89
90
91close socket
92stream_set_blocking
93Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d
94
95socket_set_block
96Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d
97
98socket_get_option
99Warning: socket_get_option(): supplied resource is not a valid Socket resource in %s on line %d
100
101
102Done.
103