1--TEST--
2socket_export_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$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
45socket_bind($sock0, '0.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', 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', 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', 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', 0);
73$stream4 = socket_export_stream($sock4);
74socket_close($sock4);
75test($stream4, $sock4);
76?>
77--EXPECTF--
78normal
79stream_set_blocking 1
80socket_set_block 1
81socket_get_option 2
82
83
84unset stream
85socket_set_block 1
86socket_get_option 2
87
88
89unset socket
90stream_set_blocking 1
91
92
93close stream
94stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
95
96socket_set_block
97Warning: socket_set_block(): unable to set blocking mode [%d]: An operation was attempted on something that is not a socket in %s on line %d
98
99socket_get_option
100Warning: socket_get_option(): Unable to retrieve socket option [%d]: An operation was attempted on something that is not a socket in %s on line %d
101
102
103
104close socket
105stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
106
107socket_set_block Error: socket_set_block(): Argument #1 ($socket) has already been closed
108
109socket_get_option Error: socket_get_option(): Argument #1 ($socket) has already been closed
110