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 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$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
45socket_bind($sock0, '0.0.0.0');
46$stream0 = socket_export_stream($sock0);
47test($stream0, $sock0);
48
49echo "\nunset stream\n";
50$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
51socket_bind($sock1, '0.0.0.0');
52$stream1 = socket_export_stream($sock1);
53unset($stream1);
54test(null, $sock1);
55
56echo "\nunset socket\n";
57$sock2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
58socket_bind($sock2, '0.0.0.0');
59$stream2 = socket_export_stream($sock2);
60unset($sock2);
61test($stream2, null);
62
63echo "\nclose stream\n";
64$sock3 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
65socket_bind($sock3, '0.0.0.0');
66$stream3 = socket_export_stream($sock3);
67fclose($stream3);
68test($stream3, $sock3);
69
70echo "\nclose socket\n";
71$sock4 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
72socket_bind($sock4, '0.0.0.0');
73$stream4 = socket_export_stream($sock4);
74socket_close($sock4);
75test($stream4, $sock4);
76
77echo "Done.\n";
78?>
79--EXPECTF--
80normal
81stream_set_blocking 1
82socket_set_block 1
83socket_get_option 2
84
85
86unset stream
87socket_set_block 1
88socket_get_option 2
89
90
91unset socket
92stream_set_blocking 1
93
94
95close stream
96stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
97
98socket_set_block
99Warning: socket_set_block(): unable to set blocking mode [%d]: %s in %s on line %d
100
101socket_get_option
102Warning: socket_get_option(): Unable to retrieve socket option [%d]: %s in %s on line %d
103
104
105
106close socket
107stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
108
109socket_set_block Error: socket_set_block(): Argument #1 ($socket) has already been closed
110
111socket_get_option Error: socket_get_option(): Argument #1 ($socket) has already been closed
112
113
114Done.
115