Annotation of embedaddon/php/ext/standard/tests/streams/stream_get_meta_data_socket_variation1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Testing 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');
                     11: if (!$client) {
                     12:        die("Unable to create socket");
                     13: }
                     14: 
                     15: /* Accept that connection */
                     16: $socket = stream_socket_accept($server);
                     17: 
                     18: echo "Write some data:\n";
                     19: fwrite($socket, "abcdefg\n1234567\nxyzxyz\n");
                     20: var_dump(stream_get_meta_data($client));
                     21: 
                     22: echo "\n\nRead a line from the client, causing data to be buffered:\n";
                     23: fgets($client);
                     24: var_dump(stream_get_meta_data($client));
                     25: 
                     26: echo "\n\nRead 3 bytes of data from the client:\n";
                     27: fread($client, 3);
                     28: var_dump(stream_get_meta_data($client));
                     29: 
                     30: echo "\n\nClose the server side socket and read the remaining data from the client:\n";
                     31: fclose($socket);
                     32: fclose($server);
                     33: while(!feof($client)) {
                     34:        fread($client, 1);
                     35: }
                     36: var_dump(stream_get_meta_data($client));
                     37: 
                     38: ?>
                     39: --EXPECTF--
                     40: Write some data:
                     41: array(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: 
                     59: Read a line from the client, causing data to be buffered:
                     60: array(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: 
                     78: Read 3 bytes of data from the client:
                     79: array(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: 
                     97: Close the server side socket and read the remaining data from the client:
                     98: array(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: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>