From abe00908afa2b7227cfd601ee948ff3b57c27eb7 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 17 Aug 2016 16:54:21 +0800 Subject: [PATCH] Fixed bug #72853 (stream_set_blocking doesn't work) Implemented PHP_STREAM_OPTION_META_DATA_API for plain_wrappers --- NEWS | 3 ++ ext/standard/tests/streams/bug72853.phpt | 59 ++++++++++++++++++++++++ main/streams/plain_wrapper.c | 14 +++++- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/streams/bug72853.phpt diff --git a/NEWS b/NEWS index 1d5e5f8189e..fdaa671f978 100644 --- a/NEWS +++ b/NEWS @@ -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 00000000000..48bd60e7a62 --- /dev/null +++ b/ext/standard/tests/streams/bug72853.phpt @@ -0,0 +1,59 @@ +--TEST-- +Bug #72853 (stream_set_blocking doesn't work) +--SKIPIF-- + +--FILE-- + 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 55f744c55de..f472bad4b9e 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; }