com php-src: Fixed bug #72853 (stream_set_blocking does n't work): NEWS ext/standard/tests/streams/bug7 2853.phpt main/streams/plain_wrapper.c
| From: | Xinchen Hui | Date: | Wed, 17 Aug 2016 08:54:21 +0000 |
| Subject: | com php-src: Fixed bug #72853 (stream_set_blocking does n't work): NEWS ext/standard/tests/streams/bug7 2853.phpt main/streams/plain_wrapper.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93869@lists.php.net to get a copy of this message | ||
Commit: abe00908afa2b7227cfd601ee948ff3b57c27eb7
Author: Xinchen Hui <laruence@gmail.com> Wed, 17 Aug 2016 16:54:21 +0800
Parents: 9e00ad2b091f3bbb6e34656c06eb7601fbadb7ce
Branches: PHP-5.6 PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=abe00908afa2b7227cfd601ee948ff3b57c27eb7
Log:
Fixed bug #72853 (stream_set_blocking doesn't work)
Implemented PHP_STREAM_OPTION_META_DATA_API for plain_wrappers
Bugs:
https://bugs.php.net/72853
Changed paths:
M NEWS
A ext/standard/tests/streams/bug72853.phpt
M main/streams/plain_wrapper.c
Diff:
diff --git a/NEWS b/NEWS
index 1d5e5f8..fdaa671 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 0000000..48bd60e
--- /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 55f744c..f472bad 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;
}