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?>
12--FILE--
13<?php
14
15function test($stream, $sock) {
16    if ($stream !== null) {
17        echo "stream_set_blocking ";
18        try {
19            print_r(stream_set_blocking($stream, 0));
20        } catch (Error $e) {
21            echo get_class($e), ": ", $e->getMessage(), "\n";
22        }
23        echo "\n";
24    }
25    if ($sock !== null) {
26        echo "socket_set_block ";
27        try {
28            print_r(socket_set_block($sock));
29        } catch (Error $e) {
30            echo get_class($e), ": ", $e->getMessage(), "\n";
31        }
32        echo "\n";
33        echo "socket_get_option ";
34        try {
35            print_r(socket_get_option($sock, SOL_SOCKET, SO_TYPE));
36        } catch (Error $e) {
37            echo get_class($e), ": ", $e->getMessage(), "\n";
38        }
39        echo "\n";
40    }
41    echo "\n";
42}
43
44echo "normal\n";
45$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
46socket_bind($sock0, '0.0.0.0', 0);
47$stream0 = socket_export_stream($sock0);
48test($stream0, $sock0);
49
50echo "\nunset stream\n";
51$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
52socket_bind($sock1, '0.0.0.0', 0);
53$stream1 = socket_export_stream($sock1);
54unset($stream1);
55test(null, $sock1);
56
57echo "\nunset socket\n";
58$sock2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
59socket_bind($sock2, '0.0.0.0', 0);
60$stream2 = socket_export_stream($sock2);
61unset($sock2);
62test($stream2, null);
63
64echo "\nclose stream\n";
65$sock3 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
66socket_bind($sock3, '0.0.0.0', 0);
67$stream3 = socket_export_stream($sock3);
68fclose($stream3);
69test($stream3, $sock3);
70
71echo "\nclose socket\n";
72$sock4 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
73socket_bind($sock4, '0.0.0.0', 0);
74$stream4 = socket_export_stream($sock4);
75socket_close($sock4);
76test($stream4, $sock4);
77?>
78--EXPECTF--
79normal
80stream_set_blocking 1
81socket_set_block 1
82socket_get_option 2
83
84
85unset stream
86socket_set_block 1
87socket_get_option 2
88
89
90unset socket
91stream_set_blocking 1
92
93
94close stream
95stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
96
97socket_set_block
98Warning: 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
99
100socket_get_option
101Warning: 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
102
103
104
105close socket
106stream_set_blocking TypeError: stream_set_blocking(): supplied resource is not a valid stream resource
107
108socket_set_block Error: socket_set_block(): Argument #1 ($socket) has already been closed
109
110socket_get_option Error: socket_get_option(): Argument #1 ($socket) has already been closed
111