Annotation of embedaddon/php/ext/standard/tests/streams/stream_get_line_nb.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: stream_get_line() on non-blocking stream
! 3: --SKIPIF--
! 4: <?php
! 5: $sockets = @stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
! 6: if (!$sockets) die("skip");
! 7: fclose($sockets[0]);
! 8: fclose($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);
! 19: var_dump($sockets);
! 20:
! 21: stream_set_blocking($sockets[1], 0);
! 22:
! 23: $eol = b'<EOL>';
! 24:
! 25: fwrite($sockets[0], b"line start");
! 26: var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
! 27: var_dump(stream_get_line($sockets[1], 8192, $eol));
! 28: fwrite($sockets[0], b", line end");
! 29: fwrite($sockets[0], b", $eol");
! 30: var_dump(stream_get_line($sockets[1], 8192, $eol)); // Returns full line (EOL found)
! 31: var_dump(stream_get_line($sockets[1], 8192, $eol)); // Nothing to read
! 32: var_dump(stream_get_line($sockets[1], 8192, $eol));
! 33:
! 34: fwrite($sockets[0], b"incomplete line");
! 35: var_dump(stream_get_line($sockets[1], strlen(b"incomplete line"), $eol)); // EOL not found but $length has been read, return incomplete line
! 36:
! 37: fwrite($sockets[0], b"incomplete line");
! 38: var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
! 39: var_dump(fread($sockets[1], strlen(b"incomplete line"))); // Returns buffer readden by stream_get_line
! 40:
! 41: fwrite($sockets[0], b"end of file");
! 42: var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
! 43:
! 44: fclose($sockets[0]);
! 45: var_dump(stream_get_line($sockets[1], 8192, $eol)); // Returns incomplete line (End of file)
! 46:
! 47: fclose($sockets[1]);
! 48:
! 49: ?>
! 50: --EXPECTF--
! 51: array(2) {
! 52: [0]=>
! 53: resource(%d) of type (stream)
! 54: [1]=>
! 55: resource(%d) of type (stream)
! 56: }
! 57: bool(false)
! 58: bool(false)
! 59: string(22) "line start, line end, "
! 60: bool(false)
! 61: bool(false)
! 62: string(15) "incomplete line"
! 63: bool(false)
! 64: string(15) "incomplete line"
! 65: bool(false)
! 66: string(11) "end of file"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>