1--TEST--
2stream_get_line() on non-blocking stream
3--SKIPIF--
4<?php
5$sockets = @stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
6if (!$sockets) die("skip stream_socket_pair() should work");
7fclose($sockets[0]);
8fclose($sockets[1]);
9?>
10--FILE--
11<?php
12/**
13 * Tests that stream_get_line() behaves as documented on non-blocking streams:
14 * Never return incomplete lines, except on documented conditions:
15 * length bytes have been read, the string specified by ending is found, EOF.
16 */
17
18$sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
19var_dump($sockets);
20
21stream_set_blocking($sockets[1], 0);
22
23$eol = '<EOL>';
24
25fwrite($sockets[0], "line start");
26var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
27var_dump(stream_get_line($sockets[1], 8192, $eol));
28fwrite($sockets[0], ", line end");
29fwrite($sockets[0], ", $eol");
30var_dump(stream_get_line($sockets[1], 8192, $eol)); // Returns full line (EOL found)
31var_dump(stream_get_line($sockets[1], 8192, $eol)); // Nothing to read
32var_dump(stream_get_line($sockets[1], 8192, $eol));
33
34fwrite($sockets[0], "incomplete line");
35var_dump(stream_get_line($sockets[1], strlen("incomplete line"), $eol)); // EOL not found but $length has been read, return incomplete line
36
37fwrite($sockets[0], "incomplete line");
38var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
39var_dump(fread($sockets[1], strlen("incomplete line"))); // Returns buffer readden by stream_get_line
40
41fwrite($sockets[0], "end of file");
42var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
43
44fclose($sockets[0]);
45var_dump(stream_get_line($sockets[1], 8192, $eol)); // Returns incomplete line (End of file)
46
47fclose($sockets[1]);
48
49?>
50--EXPECTF--
51array(2) {
52  [0]=>
53  resource(%d) of type (stream)
54  [1]=>
55  resource(%d) of type (stream)
56}
57bool(false)
58bool(false)
59string(22) "line start, line end, "
60bool(false)
61bool(false)
62string(15) "incomplete line"
63bool(false)
64string(15) "incomplete line"
65bool(false)
66string(11) "end of file"
67