summaryrefslogtreecommitdiff
path: root/main/streams/plain_wrapper.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2014-09-29 16:27:33 +0200
committerAnatol Belski <ab@php.net>2014-09-29 16:27:33 +0200
commit87a37f40909907b077cce213c0f38d7f24a29916 (patch)
treecf9703bf244bc52ed9dfd7b7f0f23ef1cc80f7f2 /main/streams/plain_wrapper.c
parenta8e84b1b21c80ec1060f5afeb146b13ddf267d3e (diff)
parent0c982798e01e5a48765aa5352f96066e77e36efd (diff)
downloadphp-git-87a37f40909907b077cce213c0f38d7f24a29916.tar.gz
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Fixed bug #51800 proc_open on Windows hangs forever
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 87312b9ef8..1969401111 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -342,6 +342,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++ < 180);
+
+ /* 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) {