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