summaryrefslogtreecommitdiff
path: root/main/streams/plain_wrapper.c
diff options
context:
space:
mode:
authorRasmus Lerdorf <rasmus@php.net>2014-10-16 21:28:40 -0700
committerRasmus Lerdorf <rasmus@php.net>2014-10-16 21:28:40 -0700
commita9d6556971a435f71eabf142d8fb814382f3b6ac (patch)
tree4fecce88bbc1bc3259856eb0314d780184de85eb /main/streams/plain_wrapper.c
parent86674b5837bffe4486714f9661620020ee498f3b (diff)
parent176b8d7ca3aef3a172d8e429627c98e0328d02d8 (diff)
downloadphp-git-a9d6556971a435f71eabf142d8fb814382f3b6ac.tar.gz
Merge branch 'master' of git.php.net:php-src
* 'master' of git.php.net:php-src: (1132 commits) Micro optimizations for isset/empty Micro optimization for zend_hash_next_index_insert_new() Fix array_keys() on $GLOBALS Fix procedural finfo calls in methods Fix allocator for 64bit zend_long with 32bit long Use intptr_t for zend_intptr_t typedef Fix format strings in zend_alloc Drop zend_long64 in favor of int64_t Removed deprecated fields NEWS cleanup NEWS removing the NEWS entry as we had to revert this fix for now Revert "Merge branch 'PHP-5.5' into PHP-5.6" Revert "fix TS build" Revert "Merge branch 'PHP-5.4' into PHP-5.5" Revert "Bug #67965: Fix blocking behavior in non-blocking crypto streams" Revert "Bug #41631: Fix regression from first attempt (6569db8)" NEWS Fixed Bug #65171 imagescale() fails Fixed bug #68234 ...
Diffstat (limited to 'main/streams/plain_wrapper.c')
-rw-r--r--main/streams/plain_wrapper.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index d9f058e3cc..28328c3cd5 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
@@ -138,7 +138,7 @@ typedef struct {
HANDLE file_mapping;
#endif
- php_stat_t sb;
+ zend_stat_t sb;
} php_stdio_stream_data;
#define PHP_STDIOP_GET_FD(anfd, data) anfd = (data)->file ? fileno((data)->file) : (data)->fd
@@ -149,7 +149,7 @@ static int do_fstat(php_stdio_stream_data *d, int force)
int r;
PHP_STDIOP_GET_FD(fd, d);
- r = php_fstat(fd, &d->sb);
+ r = zend_fstat(fd, &d->sb);
d->cached_fstat = r == 0;
return r;
@@ -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, PLAIN_WRAP_BUF_SIZE(count));
if (ret == (size_t)-1 && errno == EINTR) {
@@ -1102,7 +1130,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
#ifndef PHP_WIN32
# ifdef EXDEV
if (errno == EXDEV) {
- php_stat_t sb;
+ zend_stat_t sb;
if (php_copy_file(url_from, url_to TSRMLS_CC) == SUCCESS) {
if (VCWD_STAT(url_from, &sb) == 0) {
# if !defined(TSRM_WIN32) && !defined(NETWARE)
@@ -1165,7 +1193,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
} else {
/* we look for directory separator from the end of string, thus hopefuly reducing our work load */
char *e;
- php_stat_t sb;
+ zend_stat_t sb;
int dir_len = strlen(dir);
int offset = 0;
char buf[MAXPATHLEN];
@@ -1336,7 +1364,7 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
break;
#endif
case PHP_STREAM_META_ACCESS:
- mode = (mode_t)*(long *)value;
+ mode = (mode_t)*(zend_long *)value;
ret = VCWD_CHMOD(url, mode);
break;
default: