summaryrefslogtreecommitdiff
path: root/main/streams/plain_wrapper.c
diff options
context:
space:
mode:
authorGeorge Wang <gwang@php.net>2014-10-03 16:43:08 -0400
committerGeorge Wang <gwang@php.net>2014-10-03 16:43:08 -0400
commitef0eed7f5ff34236b39d9c5914e1627ef30c7cb7 (patch)
treeaa1b356321816109d462cacbb0c7986e3abe3153 /main/streams/plain_wrapper.c
parent0cc2600ec64d882df7f44390bfd5411750f86947 (diff)
parentd67c05bb899f4db42dd568376112b9144de2b5f1 (diff)
downloadphp-git-ef0eed7f5ff34236b39d9c5914e1627ef30c7cb7.tar.gz
Merge branch 'PHP-5.5' of git.php.net:php-src into PHP-5.5
Diffstat (limited to 'main/streams/plain_wrapper.c')
-rw-r--r--main/streams/plain_wrapper.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index a50662b78e..4b5dc55276 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -348,6 +348,34 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS
assert(data != NULL);
if (data->fd >= 0) {
+#ifdef PHP_WIN32
+ php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract;
+
+ if (self->is_pipe || self->is_process_pipe) {
+ HANDLE ph = (HANDLE)_get_osfhandle(data->fd);
+ int retry = 0;
+ DWORD avail_read = 0;
+
+ do {
+ /* Look ahead to get the available data amount to read. Do the same
+ as read() does, however not blocking forever. In case it failed,
+ no data will be read (better than block). */
+ if (!PeekNamedPipe(ph, NULL, 0, NULL, &avail_read, NULL)) {
+ break;
+ }
+ /* If there's nothing to read, wait in 100ms periods. */
+ if (0 == avail_read) {
+ usleep(100000);
+ }
+ } while (0 == avail_read && retry++ < 320);
+
+ /* Reduce the required data amount to what is available, otherwise read()
+ will block.*/
+ if (avail_read < count) {
+ count = avail_read;
+ }
+ }
+#endif
ret = read(data->fd, buf, count);
if (ret == (size_t)-1 && errno == EINTR) {