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:31337');
8
9/* Connect to it */
10$client = fsockopen('tcp://127.0.0.1:31337');
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  ["stream_type"]=>
43  string(%d) "tcp_socke%s"
44  ["mode"]=>
45  string(2) "r+"
46  ["unread_bytes"]=>
47  int(0)
48  ["seekable"]=>
49  bool(false)
50  ["timed_out"]=>
51  bool(false)
52  ["blocked"]=>
53  bool(true)
54  ["eof"]=>
55  bool(false)
56}
57
58
59Read a line from the client, causing data to be buffered:
60array(7) {
61  ["stream_type"]=>
62  string(%d) "tcp_socke%s"
63  ["mode"]=>
64  string(2) "r+"
65  ["unread_bytes"]=>
66  int(15)
67  ["seekable"]=>
68  bool(false)
69  ["timed_out"]=>
70  bool(false)
71  ["blocked"]=>
72  bool(true)
73  ["eof"]=>
74  bool(false)
75}
76
77
78Read 3 bytes of data from the client:
79array(7) {
80  ["stream_type"]=>
81  string(%d) "tcp_socke%s"
82  ["mode"]=>
83  string(2) "r+"
84  ["unread_bytes"]=>
85  int(12)
86  ["seekable"]=>
87  bool(false)
88  ["timed_out"]=>
89  bool(false)
90  ["blocked"]=>
91  bool(true)
92  ["eof"]=>
93  bool(false)
94}
95
96
97Close the server side socket and read the remaining data from the client:
98array(7) {
99  ["stream_type"]=>
100  string(%d) "tcp_socke%s"
101  ["mode"]=>
102  string(2) "r+"
103  ["unread_bytes"]=>
104  int(0)
105  ["seekable"]=>
106  bool(false)
107  ["timed_out"]=>
108  bool(false)
109  ["blocked"]=>
110  bool(true)
111  ["eof"]=>
112  bool(true)
113}
114