1--TEST--
2socket_export_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$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
34socket_bind($sock0, '0.0.0.0', 58380);
35$stream0 = socket_export_stream($sock0);
36test($stream0, $sock0);
37
38echo "\nunset stream\n";
39$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
40socket_bind($sock1, '0.0.0.0', 58381);
41$stream1 = socket_export_stream($sock1);
42unset($stream1);
43test(null, $sock1);
44
45echo "\nunset socket\n";
46$sock2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
47socket_bind($sock2, '0.0.0.0', 58382);
48$stream2 = socket_export_stream($sock2);
49unset($sock2);
50test($stream2, null);
51
52echo "\nclose stream\n";
53$sock3 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
54socket_bind($sock3, '0.0.0.0', 58383);
55$stream3 = socket_export_stream($sock3);
56fclose($stream3);
57test($stream3, $sock3);
58
59echo "\nclose socket\n";
60$sock4 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
61socket_bind($sock4, '0.0.0.0', 58484);
62$stream4 = socket_export_stream($sock4);
63socket_close($sock4);
64test($stream4, $sock4);
65
66echo "Done.\n";
67--EXPECTF--
68normal
69stream_set_blocking 1
70socket_set_block 1
71socket_get_option 2
72
73
74unset stream
75socket_set_block 1
76socket_get_option 2
77
78
79unset socket
80stream_set_blocking 1
81
82
83close stream
84stream_set_blocking
85Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d
86
87socket_set_block
88Warning: socket_set_block(): unable to set blocking mode [%d]: An operation was attempted on something that is not a socket.
89 in %s on line %d
90
91socket_get_option
92Warning: socket_get_option(): unable to retrieve socket option [%d]: An operation was attempted on something that is not a socket.
93 in %s on line %d
94
95
96
97close socket
98stream_set_blocking
99Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d
100
101socket_set_block
102Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d
103
104socket_get_option
105Warning: socket_get_option(): supplied resource is not a valid Socket resource in %s on line %d
106
107
108Done.
109