1--TEST--
2Testing stream_get_meta_data() "unread_bytes" field on a udp socket
3--FILE--
4<?php
5
6/* Setup socket server */
7$server = stream_socket_server('tcp://127.0.0.1:31331');
8
9/* Connect to it */
10$client = fsockopen('tcp://127.0.0.1:31331');
11if (!$client) {
12	die("Unable to create socket");
13}
14
15/* Accept that connection */
16$socket = stream_socket_accept($server);
17
18echo "Write some data:\n";
19fwrite($socket, "abcdefg\n1234567\nxyzxyz\n");
20var_dump(stream_get_meta_data($client));
21
22echo "\n\nRead a line from the client, causing data to be buffered:\n";
23fgets($client);
24var_dump(stream_get_meta_data($client));
25
26echo "\n\nRead 3 bytes of data from the client:\n";
27fread($client, 3);
28var_dump(stream_get_meta_data($client));
29
30echo "\n\nClose the server side socket and read the remaining data from the client:\n";
31fclose($socket);
32fclose($server);
33while(!feof($client)) {
34	fread($client, 1);
35}
36var_dump(stream_get_meta_data($client));
37
38?>
39--EXPECTF--
40Write some data:
41array(7) {
42  ["timed_out"]=>
43  bool(false)
44  ["blocked"]=>
45  bool(true)
46  ["eof"]=>
47  bool(false)
48  ["stream_type"]=>
49  string(%d) "tcp_socke%s"
50  ["mode"]=>
51  string(2) "r+"
52  ["unread_bytes"]=>
53  int(0)
54  ["seekable"]=>
55  bool(false)
56}
57
58
59Read a line from the client, causing data to be buffered:
60array(7) {
61  ["timed_out"]=>
62  bool(false)
63  ["blocked"]=>
64  bool(true)
65  ["eof"]=>
66  bool(false)
67  ["stream_type"]=>
68  string(%d) "tcp_socke%s"
69  ["mode"]=>
70  string(2) "r+"
71  ["unread_bytes"]=>
72  int(15)
73  ["seekable"]=>
74  bool(false)
75}
76
77
78Read 3 bytes of data from the client:
79array(7) {
80  ["timed_out"]=>
81  bool(false)
82  ["blocked"]=>
83  bool(true)
84  ["eof"]=>
85  bool(false)
86  ["stream_type"]=>
87  string(%d) "tcp_socke%s"
88  ["mode"]=>
89  string(2) "r+"
90  ["unread_bytes"]=>
91  int(12)
92  ["seekable"]=>
93  bool(false)
94}
95
96
97Close the server side socket and read the remaining data from the client:
98array(7) {
99  ["timed_out"]=>
100  bool(false)
101  ["blocked"]=>
102  bool(true)
103  ["eof"]=>
104  bool(true)
105  ["stream_type"]=>
106  string(%d) "tcp_socke%s"
107  ["mode"]=>
108  string(2) "r+"
109  ["unread_bytes"]=>
110  int(0)
111  ["seekable"]=>
112  bool(false)
113}
114