diff options
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/standard/tests/streams/bug72853.phpt | 59 | ||||
-rw-r--r-- | main/streams/plain_wrapper.c | 14 |
3 files changed, 75 insertions, 1 deletions
@@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2016, PHP 5.6.26 +- Streams: + . Fixed bug #72853 (stream_set_blocking doesn't work). (Laruence) + - FTP: . Fixed bug #70195 (Cannot upload file using ftp_put to FTPES with require_ssl_reuse). (Benedict Singer) diff --git a/ext/standard/tests/streams/bug72853.phpt b/ext/standard/tests/streams/bug72853.phpt new file mode 100644 index 0000000000..48bd60e7a6 --- /dev/null +++ b/ext/standard/tests/streams/bug72853.phpt @@ -0,0 +1,59 @@ +--TEST-- +Bug #72853 (stream_set_blocking doesn't work) +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == 'WIN' ) { + die('skip not for windows'); +} +?> +--FILE-- +<?php + +$descs = array( + 0 => array('pipe', 'r'), // stdin + 1 => array('pipe', 'w'), // stdout +); + +$p = proc_open("ls", $descs, $pipes, '.', NULL, NULL); + +stream_set_blocking($pipes[1], false); +var_dump(stream_get_meta_data($pipes[1])); +stream_set_blocking($pipes[1], true); +while ($outs = fgets($pipes[1], 1024)) { +} +var_dump(stream_get_meta_data($pipes[1])); +proc_close($p); +?> +--EXPECTF-- +array(7) { + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(false) + ["eof"]=> + bool(false) + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "r" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) +} +array(7) { + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(true) + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "r" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) +} diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 55f744c55d..f472bad4b9 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -818,7 +818,19 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; } } - + case PHP_STREAM_OPTION_META_DATA_API: + if (fd == -1) + return -1; +#ifdef O_NONBLOCK + flags = fcntl(fd, F_GETFL, 0); + + add_assoc_bool((zval*)ptrparam, "timed_out", 0); + add_assoc_bool((zval*)ptrparam, "blocked", (flags & O_NONBLOCK)? 0 : 1); + add_assoc_bool((zval*)ptrparam, "eof", stream->eof); + + return PHP_STREAM_OPTION_RETURN_OK; +#endif + return -1; default: return PHP_STREAM_OPTION_RETURN_NOTIMPL; } |