Skip to content

Commit abe0090

Browse files
committed
Fixed bug #72853 (stream_set_blocking doesn't work)
Implemented PHP_STREAM_OPTION_META_DATA_API for plain_wrappers
1 parent 9e00ad2 commit abe0090

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2016, PHP 5.6.26
44

5+
- Streams:
6+
. Fixed bug #72853 (stream_set_blocking doesn't work). (Laruence)
7+
58
- FTP:
69
. Fixed bug #70195 (Cannot upload file using ftp_put to FTPES with
710
require_ssl_reuse). (Benedict Singer)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
Bug #72853 (stream_set_blocking doesn't work)
3+
--SKIPIF--
4+
<?php
5+
if(substr(PHP_OS, 0, 3) == 'WIN' ) {
6+
die('skip not for windows');
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
12+
$descs = array(
13+
0 => array('pipe', 'r'), // stdin
14+
1 => array('pipe', 'w'), // stdout
15+
);
16+
17+
$p = proc_open("ls", $descs, $pipes, '.', NULL, NULL);
18+
19+
stream_set_blocking($pipes[1], false);
20+
var_dump(stream_get_meta_data($pipes[1]));
21+
stream_set_blocking($pipes[1], true);
22+
while ($outs = fgets($pipes[1], 1024)) {
23+
}
24+
var_dump(stream_get_meta_data($pipes[1]));
25+
proc_close($p);
26+
?>
27+
--EXPECTF--
28+
array(7) {
29+
["timed_out"]=>
30+
bool(false)
31+
["blocked"]=>
32+
bool(false)
33+
["eof"]=>
34+
bool(false)
35+
["stream_type"]=>
36+
string(5) "STDIO"
37+
["mode"]=>
38+
string(1) "r"
39+
["unread_bytes"]=>
40+
int(0)
41+
["seekable"]=>
42+
bool(false)
43+
}
44+
array(7) {
45+
["timed_out"]=>
46+
bool(false)
47+
["blocked"]=>
48+
bool(true)
49+
["eof"]=>
50+
bool(true)
51+
["stream_type"]=>
52+
string(5) "STDIO"
53+
["mode"]=>
54+
string(1) "r"
55+
["unread_bytes"]=>
56+
int(0)
57+
["seekable"]=>
58+
bool(false)
59+
}

main/streams/plain_wrapper.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,19 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
818818
return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
819819
}
820820
}
821-
821+
case PHP_STREAM_OPTION_META_DATA_API:
822+
if (fd == -1)
823+
return -1;
824+
#ifdef O_NONBLOCK
825+
flags = fcntl(fd, F_GETFL, 0);
826+
827+
add_assoc_bool((zval*)ptrparam, "timed_out", 0);
828+
add_assoc_bool((zval*)ptrparam, "blocked", (flags & O_NONBLOCK)? 0 : 1);
829+
add_assoc_bool((zval*)ptrparam, "eof", stream->eof);
830+
831+
return PHP_STREAM_OPTION_RETURN_OK;
832+
#endif
833+
return -1;
822834
default:
823835
return PHP_STREAM_OPTION_RETURN_NOTIMPL;
824836
}

0 commit comments

Comments
 (0)